how to compare str and the + sign
LINE 15 please help me
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>

int main ()
{
int i;
char str[256];

printf ("Enter a number: ");
gets ( str );
i = atoi ( str );
if(isalpha(str[256]))
{
*/if(strcmp(str,'+')==0)
{
printf("That is a plus sign");
}
}
else
printf("That is digit");
system("pause");
}

String compare (strcmp()), compares strings, not a string and a char.

Remember what a string is - a group of contiguous char's, with a terminating NULL char (generally written as '\0', but sometimes just as a 0 (zero).

So '+' can't work - it's just one char. "+" could work, because it's the string literal char + which the compiler has placed a terminating null char, right behind it (which you can't see, and that is the source of a lot of confusion).

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.