0

just having a bit of an issue on a simple problem, m meant to read in a string and return the characters using the fgets method, this is what i have come up with, i get wierd outputs, ex commas, etc, cn sum1 help me plz

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

int main(){
    char input[5];
    
    int i = 0;

	printf("Enter a string: ");
	fgets ( input, 5, stdin );
    
    printf("%c\n", &input);
	system("Pause");
	return 0;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by HiHe
0

Try this:

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

// some reasonable string size
#define MAX 50

int main(){
    char input[MAX];
    int i = 0;

    printf("Enter a string: ");
    fgets ( input, MAX, stdin );
    
    printf("%s\n", input);
    system("Pause");
    return 0;
}

You might want to replace system("Pause"); I think it only works on Win machines.

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.