I'm having an issue with my program when taking in a string.

I have two variables (ones for testing), char xpr[50] and char tst[50].
xpr gets it string by fgets --- fgets(xpr,50, stdin);
tst gets it value by strcpy --- strcpy(tst, "((1 + (2 * 3))*(2*3))");

when prompt, I put the same value ((1 + (2 * 3))*(2*3)) in xpr.

The problem is that the strcmp(xpr,tst) is greater than 0 instead of equal to 0.

Any ideas?

Recommended Answers

All 2 Replies

Could it be the new line character in the fgets() fetched c-string.

I think you might be on to something. I did a loop through all the characters and when it hit the last character, it jumped to the next line. I guess I gotta trim it out.

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.