0

I want to read an amount of string from the file
Given inputfile.txt
Micheal
Tammy
Alex

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	FILE* input;
        char name[100];
	char temp[100];

	input = fopen("inputfile.txt", "r");
	while((fscanf(input,"%c ", &name[i]))==1)
	{
		printf("%c ", name[i]);
		temp[i] = name[i];
		i++;
	}
}
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by tyliang
0

Sorry my poor english.
Given a file named inputfile.txt
Inside got string
Michael
Tammy
Alex

I want to know the code how to read and print each name.
Mine now prints M i c h a e l T a m m y A l e x

0

I solve it already. Thanks for the concern.

Given inputfile.txt
Micheal
Tammy
Alex

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	FILE* input;
	int i=0;
	char name[100];

	input = fopen("inputfile.txt", "r");
	while((fscanf(input,"%s", name))==1)
	{
	printf("The first word in the file is %s\n", name);
	}
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.