comparing strings with asciis and take warnings and unecpected output

+2 Vaggelis Dou · January 17, 2016
i have the following code and i want to compare the contents of an array of chars one by one with some ascii codes and if they match do some things.I use fgets to read from stdinn and fill buff. I gave "name" in input but i take "aaaa" in output,

    for (i=0; i<length; i++) {
if ((buf>='0' && buf<='31') || buf=='127') {
if (buf=='9') {
buf='32';
} else if (buf!='10') {
for (j=i; j<length; j++) {
buf[j]=buf[i+1];
}
}
}  else if (buf=='#') {
pb=calloc(100,sizeof(char));
}
}
puts(buf);

But i take this warnings
/images/forum/upload/2016-01-17/d27753ec1ae83b31f3e15c9f8e901a28.JPG

Post a Reply

Replies

Oldest  Newest  Rating
0 kuldeep kanzariya · February 19, 2016
Can u please give Full Code
0 Linguist Llama · January 18, 2016
If you're going to ask for help over the internet, it is important that they be able to reproduce the issue. At the moment we can't reproduce your issue; if we try to compile your code as it stands we'll get error messages that aren't what you're asking about.

Let us focus on producing a minimal, compilable and verifiable example, since it seems so hard to get this right. Start with minimal and compilable: A blank entry point.

int main(void) { }


It's minimal? Check.

It's compilable? Check.

It's verifiable? Does it reproduce your problem? No. We have to add that in. There is an element of trial and error here; you can't just copy and paste thousands of lines into the entry point to make it verifiable while sacrificing the above two checks. edit: Well, you could... but do you think we'll sit here reading anything more than 50 lines? It's best for you if you can reduce your testcase as much as possible.

I'm going to hazard a guess that your compiler is warning you about the multiple characters in character constants such as '31' and '127'.

#include <stdio.h>
int main(void) { putchar('31'); }


Minimal? Check. It's only two lines.

Compilable? Check.

Verifiable? Did this reproduce your warning? Check. These two lines are all you should have pasted.

Did you perhaps mean to write 31 (without the quotes) or '\31' (with the backslash, equivalent to without the quotes)?
  • 1

C

107,179 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator