please help with this program i dont know whats wrong.

#include <stdio.h>
#include "strlib.h"
#include "simpio.h"
#include "genlib.h"
#include "string.h"

void reverse(void);

int main()
{
	printf("Please enter a sentence and end the sentence with a -\n");
	reverse();
	system("Pause");
}

void reverse(void)
{
	int ch;
	
	if(getchar(ch) != EOF)
	{
		reverse();
		putchar(ch);
	}
}

>please help with this program i dont know whats wrong.
This is what's wrong with it.

#include "strlib.h"
#include "simpio.h"
#include "genlib.h"
#include "string.h"

None of them are necessary. if(getchar(ch) != EOF) getchar() doesn't accept arguments, and returns an int. i.e. if ((ch = getchar()) != EOF) reverse() doesn't live up to expectation as a recursive function.

if(getchar(ch) != EOF)
	{
		reverse();
		putchar(ch);
	}

It keeps calling itself and then the only character that gets "displayed" by putchar() is EOF, which you can not see. system("Pause"); Bad call there, a simple getchar(); would had sufficed. int main() needs a returned int at exit.

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.