Reading data in from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dru
    New Member
    • Sep 2006
    • 29

    Reading data in from a file

    I am trying to read data in to a struct from a prototype

    My Code is:
    Code:
    void init(student_record db[],int *count)
    {
    	FILE *input;
    	char temp_str[30];
    	input = fopen("mydata.txt","r");
    	
    	while(!feof(input) && count<SIZE)
    	{
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].firstname,temp_str);
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].lastname,temp_str);
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].ssno,temp_str);
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].city,temp_str);
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].state,temp_str);
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].year,temp_str);
    		fscanf_s(input,"%s",temp_str);
    		strcpy_s(db[*count].sex,temp_str);
    		fclose(input);
    	}
    }
    My complier is saying this:
    error C2198: 'strcpy_s' : too few arguments for call
    warning C4047: 'function' : 'rsize_t' differs in levels of indirection from 'char [30]'
    warning C4024: 'strcpy_s' : different types for formal and actual parameter 2

    Anyone have any ideas????
  • dru
    New Member
    • Sep 2006
    • 29

    #2
    anyone got any ideas?

    Comment

    • onlivimal
      New Member
      • Nov 2006
      • 3

      #3
      Originally posted by dru
      I am trying to read data in to a struct from a prototype

      My Code is:
      Code:
      void init(student_record db[],int *count)
      {
      	FILE *input;
      	char temp_str[30];
      	input = fopen("mydata.txt","r");
      	
      	while(!feof(input) && count<SIZE)
      	{
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].firstname,temp_str);
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].lastname,temp_str);
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].ssno,temp_str);
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].city,temp_str);
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].state,temp_str);
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].year,temp_str);
      		fscanf_s(input,"%s",temp_str);
      		strcpy_s(db[*count].sex,temp_str);
      		fclose(input);
      	}
      }
      My complier is saying this:
      error C2198: 'strcpy_s' : too few arguments for call
      warning C4047: 'function' : 'rsize_t' differs in levels of indirection from 'char [30]'
      warning C4024: 'strcpy_s' : different types for formal and actual parameter 2

      Anyone have any ideas????
      "strcpy" (string copy) thorws error on integer and float variables... ! check on it may be!

      Comment

      • dru
        New Member
        • Sep 2006
        • 29

        #4
        do you know another way?

        Comment

        Working...