Program Must C C Java Issues Writing Program Read File Named Test Store Array Print Word T Q37060649

Program must be in C (not C++ or java)

I am having issues writing a program to read in a file namedtest store it into an array and then print each word.

test contains 10 words some with different spaces examplebelow

first second third

banana apple

rockstar monster surge test program

thanks in advance


Answer


#include <stdio.h> 1 2 #include <stdlib.h> 4 int main() 6 FILE *fptr- fopen(file.txt, r) 9 int count - e; 8 char strings[1

#include <stdio.h>

#include <stdlib.h>

int main()

{

FILE *fptr = fopen(“file.txt”,”r”);

char strings[10][20];

int count = 0;

while( fscanf(fptr, “%s”, strings[count]) != EOF )

count++;

int i=0;

for(; i<10; i++)

printf(“%sn”, strings[i]);

return 0;

}

/*OUTPUT

first

second

third

banana

apple

rockstar

monster

surge

test

program

*/

#include <stdio.h> 1 2 #include

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.