Works when executed as main, but not when called by main - c

I was attempting to read a CSV file with the readCsv() function defined below. I happened to observe that when the readCsv() function is called within the main() function,
I end up experiencing a runtime error and the function readCsv() fails to work properly. By contrast, when I instead rename the readCsv() function to main() (of course having commented the main()
function first), the program works perfectly. But now I'm stuck because I need to be able
to call the readCsv() function within main().
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int readCsv(void)
{
int n = 0;
while(n == 0)
{
do{
printf("Enter the index of the student you want to query:");
scanf("%i",&n);
while(getchar() != '\n')
{
continue;
}
}while((isdigit(n)) != 0);
}
n++;
FILE* fp;
fp = fopen("students.csv","r+");
if ((fp == NULL)) exit(1);
char buffer[1024];
int row,column = 0;
while(fgets(buffer,1024,fp))
{
column = 0;
row++;
if(row != n)
{
continue;
}
else if (row == n)
{
char* value = strtok(buffer,",");
while(value)
{
if (column == 0)
{
printf("\nIndex:");
}
if (column == 1)
{
printf("\tName:");
}
if (column == 2)
{
printf("\tAge:");
}
if (column == 3)
{
printf("\tphone:");
}
printf("%s",value);
value = strtok(NULL,",");
column++;
}
printf("\n");
break;
}
else
{
printf("None of the conditions are true");
break;
}
}
fclose(fp);
return 0;
}
void main(void)
{
readCsv();
}

It's easy to get lost when one function tries to do everything: file open/close, user input, read from file, search for target, output results, handle problems.
Here's a snippet of your function modified to demonstrate how these operations may be handled in a more obvious (imho) sequence.
bool found = false;
while( !found && fgets(buffer,1024,fp) )
{
if( atoi( buffer ) == n ) // 'Index' is first value of each row
found = true;
}
fclose(fp);
if( !found )
{
printf("None of the conditions are true");
return 0;
}
int column = 0;
char* value = strtok(buffer,",");
/*
output fields of this row that are in buffer[]
Or, pass buffer[] to a separate function that prints the fields.
*/
return 1;

Related

Function is not correctly incrementing variable by 1

I have a function that returns the number of lines, characters, and words in an array. For some reason, when i loop through the array to print the values I am only getting the corrrect value for lines, the characters and words are returning as 0. All the functions are predetermined by my professor and my job is to fill them in.
int main(int argc, char **argv)
{
int *myArray = get_counts(argv[1]);
for (int i = 0; i < 3; i++)
{
printf("%d\n", myArray[i]);
}
return 0;
}
int *get_counts(char *filename)
{
FILE *file;
file = fopen(filename, "r");
if (file == NULL)
{
printf("NULL FILE");
}
char c;
int h;
bool whitespace = true;
static int arr[3] = {0,0,0};
do
{
c = fgetc(file);
if (c == '\n')
{
arr[0] ++;
}
}while (c != EOF);
while (true)
{
h = fgetc(file);
if (feof(file))
{
break;
}
else if (ferror(file))
{
printf("error reading file");
}
arr[2] ++;
if (whitespace && !isspace(h))
{
arr[1] ++;
whitespace = false;
}
else if (!whitespace &&isspace(h))
{
whitespace = true;
}
}
fclose(file);
return arr;
}
The best option is probably to just iterate through the file in one loop (you could also rewind() after the first loop). Use the return value of fgetc() to determine of you are at EOF instead of separate feof() calls. I also made the the result array an (out) argument instead of using a static variable (the latter is not reentrant if you ever want to call this from multiple threads and it's easy to do):
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
void get_counts(char *filename, int arr[3]) {
memset(arr, 0, 3 * sizeof(int));
FILE *file = fopen(filename, "r");
if (file == NULL) {
printf("NULL FILE");
return;
}
bool whitespace = true;
for(;;) {
int c = fgetc(file);
if(c == EOF)
break;
else if(c == '\n')
arr[0]++;
else if (whitespace && !isspace(c)) {
arr[1]++;
whitespace = false;
} else if (!whitespace && isspace(c))
whitespace = true;
arr[2]++;
}
fclose(file);
}
int main(int argc, char **argv) {
int myArray[3];
get_counts(argv[1], myArray);
for (int i = 0; i < 3; i++) {
printf("%d\n", myArray[i]);
}
}
The output on the above file is:
39
94
715
The word count 94 doesn't agree with wc -w but you could be using a different definition of what a word is.
It's a good idea to separate calculations and i/o, so consider opening and closing the file in main() and pass in the file handle. It becomes easy, for instance, to use the stdin file handle instead if you don't want to use a physical file.
After the first do-while loop the condition EOF occurs.
do
{
c = fgetc(file);
if (c == '\n')
{
arr[0] ++;
}
}while (c != EOF);
So the following while loop has no effect.
You should use only one loop to count lines, words and characters.
Pay attention to that the variable c should be declared as having the type int
int c;
Also you need to exit the function if the file was not opened.

Why does getw not display all of the numbers in the file?

I have followed this tutorial to implement a program that generates up to 100,000 random numbers and inserts them in a file to be sorted, but I have noticed that the loop with getw is outputting way less numbers than expected. In my machine, this code only prints 49 numbers:
#include <stdio.h>
#include <stdlib.h>
int gen_random_file(int n_values) {
int index;
int num, num_count = 0;
FILE *r_file;
r_file = fopen("random_numbers", "w");
if (r_file != NULL) {
printf("File created successfully!\n");
}
else {
printf("Failed to create the file.\n");
return -1;
}
for (index = 0; index < n_values; index++) {
putw(rand(), r_file);
}
fclose(r_file);
r_file = fopen("random_numbers", "r");
// display numbers
printf("\nNumbers:\n");
while ( (num = getw(r_file)) != EOF ) {
printf("%d\n", num);
num_count++;
}
printf("\nEnd of file.\nNum Count = %d\n", num_count);
fclose(r_file);
return 0;
}
int main()
{
gen_random_file(10000);
return 0;
}
You terminate the loop too early. rand() is likely to produce -1 once in a while.
Quoting man getw (section Bugs):
Since EOF is a valid integer value, feof(3) and ferror(3) must be used to check for failure after calling getw().
You need something like
while(1) {
if ((w = getw()) == EOF) {
if (feof(stdin) || ferror(stdin)) {
break;
}
printf(....);
....
}
// Deal with error if necessary
This one of those rare cases where you actually want feof. You need a loop like
while ((num = getw(r_file)), !feof(r_rile)) {
to read a number and then test for EOF.
On some systems (such as Windows), you'll also need "wb" and "rb" for your fopen modes to get a binary file.
I ended up using fwrite and fread as well as "wb" and "wr" as parameters for fopen and that solved the problem.
#include <stdio.h>
#include <stdlib.h>
int gen_random_file(int n_values) {
int index;
int rand_num, num_count = 0;
int buffer[100000];
FILE *rand_file;
rand_file = fopen("random_numbers", "wb");
if (rand_file != NULL) {
printf("File created successfully!\n");
}
else {
printf("Failed to create the file.\n");
return -1;
}
for (index = 0; index < n_values; index++) {
rand_num = rand();
fwrite(&rand_num, sizeof(rand_num), 1, rand_file);
}
fclose(rand_file);
rand_file = fopen("random_numbers", "rb");
// display numbers
printf("\nNumbers:\n");
fseek(rand_file, 0, SEEK_SET);
fread(buffer, sizeof(rand_num), n_values, rand_file);
for (index = 0; index < n_values; index++) {
rand_num = buffer[index];
printf("%d\n", rand_num);
num_count++;
}
printf("\nEnd of file.\nNum Count = %d\n", num_count);
fclose(rand_file);
return 0;
}
int main()
{
gen_random_file(10000);
return 0;
}

Check if file contains content from another file C

So I'm working on a project, and I need to check whether or not a certain file contains the contents of another file.
I made a function in c (It's c not c++) to try and to it but it seems to get into an infinite loop and not work overall, I tried using the Visual Studio debugger, and it didn't give me more info.
Note: I am including stdlib.h
the code:
int findFileInFile(const char* wherePath, const char* whatPath)
{
FILE* fpBigger = fopen(wherePath, "r");
FILE* fpSmaller = fopen(whatPath, "r");
if (fpBigger != NULL && fpSmaller != NULL)
{
unsigned char cs = 0;
unsigned char cb = 0;
while ((cb = fgetc(fpBigger)) != EOF)
{
cs = fgetc(fpSmaller);
if (cs == EOF)
return 1;
if (cs != cb)
{
fseek(fpSmaller, 0L, SEEK_SET);
}
}
return 0;
}
else
{
printf("File names are wrong!\n");
exit(-1);
}
}
Thank you.
I guess this is what you're looking for:
#include <stdio.h>
#include <stdlib.h>
int findFileInFile(const char *wherePath, const char *whatPath)
{
FILE *fpBigger = fopen(wherePath, "rb");
FILE *fpSmaller = fopen(whatPath, "rb");
if (fpBigger != NULL && fpSmaller != NULL)
{
unsigned char cs = 0;
unsigned char cb = 0;
int s;
int b;
while (1)
{
b = fgetc(fpBigger);
s = fgetc(fpSmaller);
if (s == EOF && b == EOF) //if both return values from fgetc are EOF, it means you've reached the end of the file which wouldn't have been possible if both of the files weren't equal
{
return 1;
}
else if (s == EOF || b == EOF)
{
return 0;
}
cs=(unsigned char)s; //casting the int to unsigned char
cb=(unsigned char)b; //casting the int to unsigned char
if (cs != cb) //compare the characters gotten from the files, if not equal, return 0
{
return 0;
}
}
}
else
{
printf("File names are wrong!\n");
exit(-1);
}
}
int main()
{
printf("%d", findFileInFile("file1.txt", "file2.txt"));
}
Last but not the least, you can also use feof() to check if the end of file stream has been reached.
Edit: (this may not be the most optimal solution but it checks if the bigger file contains the smaller file)
#include <stdio.h>
#include <stdlib.h>
int findFileInFile(const char *wherePath, const char *whatPath)
{
FILE *fpBigger = fopen(wherePath, "rb");
FILE *fpSmaller = fopen(whatPath, "rb");
unsigned char cs = 0;
unsigned char cb = 0;
int s;
int b;
int loc;
if (fpBigger != NULL && fpSmaller != NULL)
{
s = fgetc(fpSmaller);
cs=(unsigned char)s;
while((b=fgetc(fpBigger))!=EOF){ //checks for the first instance of the first character of the smaller file in the bigger file
cb=(unsigned char)b;
if(cs==cb){
loc=ftell(fpBigger)-1; //set loc to the position where the first character of the smaller file is found in the bigger file
break;
}
}
if(b==EOF){ //if the character is not found, return 0
return 0;
}
fseek(fpBigger,loc,SEEK_SET);
rewind(fpSmaller);
while((b=fgetc(fpBigger))!=EOF){
if((s=fgetc(fpSmaller))==EOF){ //check if the end of smaller file is reached, and return 1 if true
return 1;
}
cs=(unsigned char)s;
cb=(unsigned char)b;
if(cs!=cb){
rewind(fpSmaller); //if the characters gotten from both the files are not equal, go to the very beginning of smaller file
loc++; //increase the position to start the search from in the bigger file by 1
fseek(fpBigger,loc,SEEK_SET);
}
}
if(b==EOF&&fgetc(fpSmaller)==EOF){
return 1;
}
return 0;
}
else
{
printf("File names are wrong!\n");
exit(-1);
}
}
int main()
{
printf("%d", findFileInFile("file1.txt", "file2.txt"));
}

Print the user input strings into a least sized user input files

Program should read list of filenames, open these files and put their handles in the array of structure, then read strings and print consecutive lines of strings to smallest files by using handles contained in array of structures.
My program puts data from all lines to only one file which is initially the smallest which is false because it should the one which is smallest with every time it prints data into the file. This is my program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
struct file_t
{
FILE* f;
int size;
}t[5];
void close_file(struct file_t* f) {
if (f == NULL || f->f == NULL) {
}
else {
fclose(f->f);
}
}
int open_file(struct file_t* f, const char* filename) {
if (f == NULL || filename == NULL) {
return 1;
}
FILE* fp;
fp = fopen(filename, "ab");
if (fp == NULL) {
return 2;
}
long int res = ftell(fp);
fclose(fp);
f->size = res;
f->f = fopen(filename, "ab+");
if (fp == NULL) {
return 2;
}
return 0;
}
struct file_t* find_min(const struct file_t* files, int size) {
if (files == NULL || size <= 0) {
return NULL;
}
int x = (files + 0)->size, i = 0, index = 0;
for (i = 0; i < size; i++) {
if ((files + i)->size <= x) {
x = (files + i)->size;
index = i;
}
}
return (struct file_t*)(files + index);
}
int main() {
puts("Input files' names:");
char tab[100];
int num = 0;
while(1==1){
if(fgets(tab, 100, stdin)==NULL||*tab=='\n'){
if (num == 0) {
printf("Couldn't open file");
return 4;
}
break;
}
int index=strlen(tab);
*(tab+index-1)='\x0';
if (strlen(tab) > 30) {
*(tab + 30) = '\x0';
}
if (open_file((t + num), tab) > 0) {
}
else {
num++;
}
}
if (num == 0) {
printf("Couldn't open file");
return 4;
}
char str[1000];
printf("Input text:");
*str = '\x0';
while (fgets(str, 1000, stdin)==NULL||*str!='\n') {
int index=strlen(str);
*(str+index-1)='\x0';
struct file_t* p = find_min(t, num);
fwrite(str, sizeof(char), strlen(str), p->f);
}
for (int i = 0; i < num; i++) {
close_file(t + i);
}
printf("File saved");
return 0;
}
There are some critical bugs that you need to resolve.
fseek(stdin, 0, SEEK_END) -- fseek normally only work on a disk file, or something reasonably similar. Please refer to this link Using fseek with a file pointer that points to stdin
As a matter of fact even fflush() won't work. fflush is something that is designed for flushing output streams, and its behavior with input streams is implementation-dependent. Please refer to this link for more details stdinflush
scanf("%[^\n]s", tab)
If you are using this in a loop or multiple times, only the first read will succeed. The reason being, the \n character is left out from the previous input, and as said earlier fflush() might not be successful in removing that \n. The further calls to scanf() will simply return without reading anything.
'\0x' If you are intending to use this as string terminator then this is not it. It is a multi-character constant with an integer value 120. Below is a vague test run
Code
#include <stdio.h>
int main()
{
if ('\0' == '\0x' )
printf("both are same\n");
printf("%d",'\0x');
}
Compilation Warnings
test.c: In function ‘main’:
test.c:5:14: warning: multi-character character constant [-Wmultichar]
5 | if ('\0' == '\0x' )
| ^~~~~
test.c:8:14: warning: multi-character character constant [-Wmultichar]
8 | printf("%d",'\0x');
| ^~~~~
Output
120
fseek(fp, 0, SEEK_END); ftell(fp); -- This should not be used to determine the file sizes. The behavior of the fseek() with SEEK_END is undetermined in the case of binary files. Please refer to this link Do not use fseek() and ftell() to compute the size of a regular file
Some Logic Errors
1) You should compute the file size every time in find_min() as it gets changed whenever you write data to the file.
2) fwrite()won't actually dump the data to file immediately. you need to call fflush().
After resolving the above issues, this is the modified code.
Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <sys/stat.h>
struct file_t
{
FILE* f;
int size;
}t[5];
void close_file(struct file_t* f) {
if (f == NULL || f->f == NULL) {
}
else {
fclose(f->f);
}
}
int open_file(struct file_t* f, const char* filename) {
if (f == NULL || filename == NULL) {
return 1;
}
f->f = fopen(filename, "a");
if (f->f == NULL)
return 2;
struct stat statbuf;
fstat(fileno(f->f), &statbuf);
f->size = statbuf.st_size;
return 0;
}
struct file_t* find_min(const struct file_t* files, int size) {
if (files == NULL || size <= 0) {
return NULL;
}
struct stat statbuf;
fstat(fileno(files->f), &statbuf);
int x = statbuf.st_size, i = 0, index = 0;
for (i = 0; i < size; i++) {
fstat(fileno((files+i)->f), &statbuf);
if (statbuf.st_size < x) {
x = statbuf.st_size;
index = i;
}
}
return (struct file_t*)(files + index);
}
int main() {
puts("Input files' names:");
char tab[100];
int num = 0;
while(1){
int c;
while (1) {
c = getc(stdin);
if (c == EOF || c == ' ')
goto user_input;
if(c != '\n')
break;
}
tab[0] = c;
if (scanf("%[^\n]s", tab+1) == EOF)
break;
if (*tab == '\0') {
if (num == 0) {
printf("Couldn't open file");
return 4;
}
break;
}
if (strlen(tab) > 30) {
*(tab + 30) = '\0';
}
if (open_file((t + num), tab) > 0) {
}
else {
num++;
}
*tab = '\0';
}
user_input:
if (num == 0) {
printf("Couldn't open file");
return 4;
}
fflush(stdin);
char str[1000];
printf("Input text:\n");
*str = '\0';
while(1) {
int c;
while(1) {
c = getc(stdin);
if (c == EOF)
goto main_exit;
if (c != '\n')
break;
}
str[0] = c;
if (scanf("%[^\n]s", str+1) == EOF)
break;
struct file_t* p = find_min(t, num);
fwrite(str, sizeof(char), strlen(str), p->f);
fflush(p->f);
}
main_exit:
for (int i = 0; i < num; i++) {
close_file(t + i);
}
printf("File saved");
return 0;
}
Terminal Session
$ ./a.out
Input files' names:
test file1.txt
test file2.txt
' '(NOTE: Space character inputted before pressing enter.)
Input text:
this is
stackoverflow
File saved
test file1.txt
this is
test file2.txt
stackoverflow
Note for breaking from the first loop (Files input). You need to enter space and then press enter (You can tweak around this).
Where are you updating the file_t->size when you write into a file?
You are calling this:
fwrite(str, sizeof(char), strlen(str), p->f);
But after that you should do p->size += strlen(str) to update its size, otherwise all file sizes are set to initial values, and hence all strings get written to a single file.
As for getting garbage data, try printing the string you are reading from scanf in the while loop.
You are using scanf to read characters until '\n', but you are not reading the '\n' itself. You need a fseek(stdin, 0, SEEK_END); in that loop as well.
Finally, why are you using syntax like this:
(files + i)->size
When you can call it more cleanly like this:
files[i].size
You code is really hard to read because of this.

My delete function deletes the wrong record of struct

I have this function which is supposed to delete the recipe requested by the user. I've always deleted records in this way, but I don't know why this time it doesn't work in the right way. Sometimes it states that there's no match but it deletes the recipe or it deletes all the recipes inside the file and I don't get it why since I basically created a temp file in which writing all the records except for the one the user wants to delete and I used a function that worked for another record so I really don't get it. Is that because the length of ingredients and procedure is not the same for all the recipes?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int stringCmpi (char *s1,char *s2);
struct _recipe
{
char name[40];
int count_i;
char ingredients[20][40];
char diff[12];
int timr;
int calories;
int count_p;
char procedure[30][500];
} recipe;
int main()
{
FILE* fbr;
FILE* temp;
char ricetta_name[] = "ricette.bin";
char temp_name[] = "temp.bin";
fbr = fopen("ricette.bin", "rb");
temp = fopen("temp.bin", "wb");
int found = 0;
char name_t[40];
int i;
char space = '\n';
if(fbr == NULL)
{
printf("Couldn't open the file.\n");
exit(1);
}
if(fbr == NULL)
{
printf("Couldn't open the file.\n");
exit(1);
}
printf("Write the name of the recipe you want to delete:\n");
fgets(name_t,sizeof(name_t),stdin);
space = getchar();
while(fread(&recipe,sizeof(recipe),1,fbr) && found == 0)
{
if(stringCmpi(name_t,recipe.name) == 0)
{
found = 1;
printf("Match found. Recipe deleted.\n");
}
else
{
fwrite(&recipe,sizeof(recipe),1,temp);
}
if(!found)
{
printf("No match.\n");
}
}
fclose(fbr);
fclose(temp);
remove(ricetta_name);
rename(temp_name,ricetta_name);
system("PAUSE");
return 0;
}
int stringCmpi (char *s1,char *s2)
{
int i=0;
for(i=0; s1[i]!='\0'; i++)
{
if( toupper(s1[i])!=toupper(s2[i]) )
return 1;
}
return 0;
}
The problem is here:
while(fread(&recipe,sizeof(recipe),1,fbr) && found == 0)
Once you find a recipe, you exit the loop, so the remaining elements are not copied to the new file. I recommend you delete the && found == 0 clause.
Furthermore:
if(!found)
{
printf("No match.\n");
}
This is actually inside the while loop, so it will report No match multiple times. Please move it outside the loop.
Proper indentation would help you see the actual structure of the program. This is how the posted program looks with consistent indentation:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int stringCmpi (char *s1,char *s2);
struct _recipe
{
char name[40];
int count_i;
char ingredients[20][40];
char diff[12];
int timr;
int calories;
int count_p;
char procedure[30][500];
} recipe;
int main()
{
FILE* fbr;
FILE* temp;
char ricetta_name[] = "ricette.bin";
char temp_name[] = "temp.bin";
fbr = fopen("ricette.bin", "rb");
temp = fopen("temp.bin", "wb");
int found = 0;
char name_t[40];
int i;
char space = '\n';
if(fbr == NULL)
{
printf("Couldn't open the file.\n");
exit(1);
}
if(fbr == NULL)
{
printf("Couldn't open the file.\n");
exit(1);
}
printf("Write the name of the recipe you want to delete:\n");
fgets(name_t,sizeof(name_t),stdin);
space = getchar();
while(fread(&recipe,sizeof(recipe),1,fbr) && found == 0)
{
if(stringCmpi(name_t,recipe.name) == 0)
{
found = 1;
printf("Match found. Recipe deleted.\n");
}
else
{
fwrite(&recipe,sizeof(recipe),1,temp);
}
if(!found)
{
printf("No match.\n");
}
}
fclose(fbr);
fclose(temp);
remove(ricetta_name);
rename(temp_name,ricetta_name);
system("PAUSE");
return 0;
}
int stringCmpi (char *s1,char *s2)
{
int i=0;
for(i=0; s1[i]!='\0'; i++)
{
if( toupper(s1[i])!=toupper(s2[i]) )
return 1;
}
return 0;
}
The program is checking that fbr is not NULL twice. Probably the second check should be for temp.
The programs stops reading and copying when the recipe to be deleted is found; this means that the following records are not copied over.
The program complains that the recipe was not found for each recipe until the desired one is found.
Suggestions:
Modify the while loop condition eliminating the && ! found, so that all records are copied except those matching the given name.
Move the check for if (! found) outside the loop.
Bonus:
The function stringCmpi() stops comparing at the end of string s1; which means that "abc" and "abcdef" will compare equal. You probably want to change return 0 to return s1 [i] != s2 [i].
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct _recipe
{
char name[40];
int count_i;
char ingredients[20][40];
char diff[12];
int timr;
int calories;
int count_p;
char procedure[30][500];
} recipe;
int main(int argc, char *argv[])
{
FILE* fbr;
FILE* temp;
char *ricetta_name = "recipe.bin";
char *temp_name = "temp.bin";
int found = 0;
char name_t[40];
// Use command line arguments if possible
if (argc == 2)
{
ricetta_name = argv[1];
}
if((fbr = fopen(ricetta_name, "rb")) == NULL)
{
printf("Couldn't open the file %s.\n", ricetta_name);
exit(1);
}
if((temp = fopen(temp_name, "wb")) == NULL)
{
printf("Couldn't open the file %s.\n", temp_name);
exit(1);
}
printf("Write the name of the recipe you want to delete:\n");
fgets(name_t, sizeof(name_t), stdin);
// Remove '\n'
if (name_t[strlen(name_t) - 1] == '\n')
name_t[strlen(name_t) - 1] = 0;
while(fread(&recipe,sizeof(recipe), 1, fbr))
{
// Use standard strcasecmp()
if(strcasecmp(name_t, recipe.name) == 0)
{
found = 1;
printf("Match found. Recipe deleted.\n");
}
else
{
fwrite(&recipe, sizeof(recipe), 1, temp);
}
}
if (!found)
{
printf("No match.\n");
}
fclose(fbr);
fclose(temp);
remove(ricetta_name);
rename(temp_name,ricetta_name);
return 0;
}
Please format your code: add space(' ') after comma(','). And use standard function if possible.

Resources