I have this input file:
I need to read this data in, and am trying to print it up on screen. At most the strings at the outputs shuld only have 9 characters... so John Longlastname... would be cut down to John Long for output.Code:
John LongLastName
143
Ann Iaeiouyhfsdf.
103
Ann X.
11
Jim C.
106
Ann B.
123
John LongLastName
143
class size 3
drop
11
103
106
I made this loop to read it in:
but the output it gives me is:Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main(){
char temp_name[30];
char dummy[30];
int ID;
while( strstr("class siz",temp_name) == NULL) {
fgets(temp_name,30,fin);
if(strlen(temp_name)>9){
temp_name[9] = '\0' ; }
fscanf(fin," %d",&ID);
printf("%s\n",temp_name);
printf("%d\n",ID);
}
Could anyone tell me what I'm doing wrong? It looks like it's trying to scan in the blank line in the input.... I don't know how to get around this....Code:John Long
143
143
Ann Iaeio
103
103
Ann X.
11
11
Jim C.
I've tried putting in a dummy fgets to take in the blank line but it didn't work
Thank You