when the user types in ls i want the program to show the listed files in his directory but it is not working i cant list the files can anyone help ? this is what i have done so far. it breaks fine when the user enters x

while(1)
		{
		printf("\ntype 'ls' to see your whats in your current directory or press x to continue ");
		scanf("%s", &input);
		if(input == 'x')
		{
		break;
		if (input != 'x')
		{
		system(input);
		break;
		
		}
	}
	}

I see a major discrepancy in your use of the input variable. Is it a char, or an array of char? Because either way you're misusing it somewhere.

Yeah you might want keep input as a c-string and use strcmp for your comparisons.

yeah it should be an array of char i have been changing trying to get it to work

this what it was

while(1)
		{
		printf("\ntype 'ls' to see your whats in your current directory or press x to continue ");
		scanf("%c", &input);
		if(input[0] == "ls")
		{
		system(input);
		continue;
		}
		else
		{
		if (input[0] != "ls")
		break;
		
		
	}

but it still does not work if i change the first if statement to if(input[0] != "ls") then ls works but i cant break out of that loop im really confused i can not seem to get it

You should use strcmp here not ==

if(input[0] == "ls")

it should be

if (!strcmp(input, "ls"))

Noone can really help you without seeing how you defined input . Why don't you post all the code? As I see from the crap you've posted, you can't have anything worth hiding from us.

thanks i never used the strcmp function before its new to me im just a beginner, so if i am right strcmp just compares the string to what is inputed by the user ?

I not getting what help you expecting from all??????

see your code

while(1)
		{
		printf("\ntype 'ls' to see your whats in your current directory or press x to continue ");
		scanf("%c", &input);
		if(input[0] == "ls")
		{
		system(input);
		continue;
		}
		else
		{
		if (input[0] != "ls")
		break;
		
		
	}

You scanning single char with %c and thn taking suggestion to use strcmp??

Dude first tell what is input???????
<b>char???
Array of char???
pointer????</b>

what is tht??

sorry my bad input is = char input[4] = "ls"; i used strcmp which did the job is there other ways of doing it than using strcmp ?

oh thts nice..
strcmp is better way stick with this but i think u need correcting on 4th line..
U scannig string so use %s and dont use address operator(&

If its working its fine :)

And if problem solved close this thread ..

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.