1
int main(){
char aux;
int i=0,j=0,p=0;
char vetor[26];
FILE *arq;
My.txt file has any string, I just want to take the characters of this string and move to a 26 position vector, which is the amount of letters you have in the alphabet. It is not the case now, but in the future I will implode a function to have no repeated characters.
arq = fopen("arquivo.txt","r");
No while I scan the entire text file and remove the ' n' and store the rest in the vector
while (fscanf(arq, "%c", &aux )!= EOF){
printf("%d %c\n",i++ ,aux);
if(aux != '\n'){
vetor[j] = aux;
j++;
}
}
printf("Print do vetor\n");
However, at the time I’m going to print all the positions of the vector, there are still some empty spaces that I don’t know what it is, and I don’t know how to treat them. Follow a screenshot below
for ( p = 0; p < j; p++){
printf("%c\n", vetor[p]);
}
fclose(arq);
return 0;
How’s the original file (.txt file) ?
– Isac
AABCDD BADCC FABD XFCX
– fabiovinicius
each space is a line break(unable to send with line break)
– fabiovinicius
Testing here on my pc appears correct. You are sure you have normal line breaks in your input file ?
– Isac
yes, have 4 lines and each row has a string
– fabiovinicius
https://i.stack.Imgur.com/Rqcvd.png
– Isac
strange , but obg by the time , I will try to see calmly here , vlw
– fabiovinicius
vlw mano, was what I was weighing, just gave a space between " and % in the function fscanf
– fabiovinicius