1
I need to make a program in C that reads an external file with characters inside and checks if the character code is between the codes >32 and <126 of the ASCII table. If it is between code 32 and 126 I return "Contains in table"+character If you are not between this code space I return "Does not contain in table"+character. I did it this way, but "Else" is returning different characters than I type.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *pont_arq;
int c=0;
char palavra[20];
pont_arq = fopen("arquivo.txt", "rt");
do
{
c = getc(pont_arq);
if (c >= 32 && c <= 126){
printf(" | %c %i contem na tabela", c, c);
}else
{
printf("\n\n %i nao contem na tabela ", c, c);
}
} while (c != EOF);
fclose(pont_arq);
return(0);
}
I understand the opening mode
r
,r+
andrb
, now what is the opening modert
used there byfopen
?– Jefferson Quesado
@Jeffersonquesado some implementations consider characters different from standard ones. In this case, the "t" would symbolize a text file (which obviously must exist). In IBM z/OS this feature is available.
– José
Show an example, preferably small, of a chunk of the input, and also of the output, that contains "different characters than the type". Note that in the Else printf you only enter the format for a variable but in the function you enter two variables.
– anonimo
The entry put "hjç" (no quotes), in this case the output was: "h 104 contains in table | j 106 contains in table | 195 does not contain in table | 167 does not contain in table | -1 does not contain in table". But the output should have been only "h 104 contains in table | j 106 contains in table | ç 135 does not contain in table".
– Samara
The standard ASCII table defines only characters from 0 to 127. It does not include accented and special characters in your case
ç
. Maybe you should work with UTF-8 character encoding (preferably) or Latin1 (ISO/IEC 8859-1) to handle characters not represented in the ASCII table.– anonimo