Skip to main content

theI've got an input file looks like this:

1 2 2 Medium 1 2 0 Medium 2 1 0 Medium 2 0 2 Medium

1 2 2 Medium 
1 2 0 Medium
2 1 0 Medium
2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???

int x,y,z; 
char* cs; 
fscanf(fp3,"%d",&x); 
fscanf(fp3,"%d",&y); 
fscanf(fp3,"%d",&z); 
fscanf(fp3,"%s",&cs);

the input file looks like this:

1 2 2 Medium 1 2 0 Medium 2 1 0 Medium 2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???

int x,y,z; 
char* cs; 
fscanf(fp3,"%d",&x); 
fscanf(fp3,"%d",&y); 
fscanf(fp3,"%d",&z); 
fscanf(fp3,"%s",&cs);

I've got an input file like this:

1 2 2 Medium 
1 2 0 Medium
2 1 0 Medium
2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???

int x,y,z; 
char* cs; 
fscanf(fp3,"%d",&x); 
fscanf(fp3,"%d",&y); 
fscanf(fp3,"%d",&z); 
fscanf(fp3,"%s",&cs);
Moved OP's code from comment into question
Source Link
egrunin
  • 25k
  • 8
  • 52
  • 94

the input file looks like this:

1 2 2 Medium 1 2 0 Medium 2 1 0 Medium 2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???

int x,y,z; 
char* cs; 
fscanf(fp3,"%d",&x); 
fscanf(fp3,"%d",&y); 
fscanf(fp3,"%d",&z); 
fscanf(fp3,"%s",&cs);

the input file looks like this:

1 2 2 Medium 1 2 0 Medium 2 1 0 Medium 2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???

the input file looks like this:

1 2 2 Medium 1 2 0 Medium 2 1 0 Medium 2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???

int x,y,z; 
char* cs; 
fscanf(fp3,"%d",&x); 
fscanf(fp3,"%d",&y); 
fscanf(fp3,"%d",&z); 
fscanf(fp3,"%s",&cs);
Source Link

reading string from a file in c

the input file looks like this:

1 2 2 Medium 1 2 0 Medium 2 1 0 Medium 2 0 2 Medium

I am using fscanf() to read in the integer values and that is working fine. does anyone have any ideas how to read in the string and place it in a string variable???