Hello

I am trying to get this function to work...

int error(const char* s)
{
	int f=1;
	
        while (*s!='/0')
       {
              if(*s=='/')
	     {
		  f=0;
		  return(f);
	     }
	      s++;
       }
return f;
}

I want to find out if in the string tat i am passing there is a character "/"....But i am getting a runtime error....wat am i doing wrong? Kindly help..
Thanks in advance...

Recommended Answers

All 3 Replies

Well for 10 lines of code, the indentation sucks.
Is the rest of your code an unreadable mess?

Do you get any warnings when you compile?

$ gcc -W -Wall -O2 -c foo.c
foo.c:5:14: warning: multi-character character constant
foo.c: In function ‘error’:
foo.c:5: warning: comparison is always true due to limited range of data type

Hint: consider the difference between /0 and \0

No, i did not get any warnings....It just encounters error while executing...However if i use "a" or some letter instead of "/"...i am not getting error...

Damn, saw ur "hint" now...sorry and thanks...

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.