The line break is a character of "escape", are characters of type "ENTER" or "TAB". In the case of line break is the " n", and can be compared like this == "\n"
, but some characters are not possible because it does not have "escape" characters, such as the case of a "DEL" for example, so one way to cover all characters is to convert the one char
for int
that will return the code ASCII
, which will be 10 and compare, so:
int ascii;
....
ascii = (int)frase[i];
if (ascii == 10) // é uma quebra de linha
You can test with this little program:
#include <stdio.h>
int main() {
int ascii, i;
char texto[] = "Bom dia\nGood Moring\nBonjour";
printf("%s\n------------\n", texto);
for(i=0; texto[i]; i++) {
ascii = (int)texto[i];
if (ascii == 10) {
printf("Quebra de linha\n");
} else {
printf("%c = %d\n",texto[i],ascii);
}
}
}
Or see online working here: https://www.mycompiler.io/view/0utzo5p
And you can see the table with the other codes ASCII
here: https://sites.google.com/a/aebenfica.org/apontamentos-tic/tic/ascii
OBS: I edited the question based on the comments to better reflect the comparison
a line break is an escape character equal to
\n
, have tried to verify comparing to this?– Ricardo Pontual
already, does not work
– Victoria Moraes