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;
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.