4

I do a simple database management project in C. But when I run this code, I get...

 2 years ago
source link: https://www.codesd.com/item/i-do-a-simple-database-management-project-in-c-but-when-i-run-this-code-i-get-an-error.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I do a simple database management project in C. But when I run this code, I get an error.

advertisements

i am trying to compare the filename given by user with the array of strings.when i run this code i get error as:
In function `add_record':
syntax error before ']' token

also,even if i remove the code from 'start' to 'stop' i get error as:
i:\gw\lib\crt2.o(.text+0x8) In function _mingw_CRTStartup':
[Linker error] undefined reference to
__dyn_tls_init_callback'
[Linker error] undefined reference to `__cpu_features_init'
i:\gw\lib\crt2.o(.text+0x8) ld returned 1 exit status

Please help me.Thank you!

void add_record()
{
 FILE *fp;
 char filename[25],fname_check[NO_OF_FILE][25];
 char tester;
 int i;

 printf("Type the name of the file you want to store the record in : ");
 scanf("%s",filename);
 //start
 for(i=0;i<sizeof(fname_check);i++)
 {
                                   if(strcmp(fname_check[i][],filename) == 0) printf("File already exists!\n");
                                   break;
                                   }
 printf("The file will be overwritten if you enter the same name.....\n");                                  

 printf("Type the name of the file you want to store the record in : ");
 scanf("%s",filename);
   //end                              

 fp = fopen(filename,"w");
 if(fp == NULL)
 {
       printf("Sorry,File cannot be opened!");
       getch();
       exit(0);
       }

 while(1)
 {
         fflush(stdin);
  printf("\nEnter name : ");
  gets(pro.name);
  printf("Enter age : ");
  scanf("%d",&pro.age);
  printf("Enter gender : ");
  gets(pro.gender);
  printf("Enter phone : ");
  scanf("%d",&pro.phone);
  printf("Enter email : ");
  gets(pro.email);
  printf("Enter location : ");
  gets(pro.location);
  printf("Enter bio : ");
  gets(pro.bio);

  printf("If you want to add more records press any key... or press ESC key... ");
  tester = getche();
  if(tester == 27) break;
 }
 fclose(fp);

}enter code here


fname_check[i][] isn't valid. All you need is fname_check[i] which is a string.

Also, you have to loop until i < sizeof(fname_check)\sizeof(fname_check[0]), since sizeof(fname_check) will give the total size of the array in bytes.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK