-2
I’m making a program to replace the vowels of a typed phrase with *
and show to user:
#include<stdio.h>
#include<string.h>
#define TAM 50
int main(){
char f[TAM];
int t_f,n;
printf("Digite a frase:\n");
fgets(f,TAM,stdin);
t_f=strlen(f);
for(n=0;n<=t_f;n++){
if((f[n]=='A') ||(f[n]=='a')|| (f[n]=='E')|| (f[n]=='e') || (f[n]=='I') || (f[n]=='i') || (f[n]=='O') || (f[n]=='o') || (f[n]=='U') || (f[n]=='u')){
f[n] ='*';
}
}
for(n=0;n<=t_f;n++){
printf("Frase criptografada:%s",f[n]);
}
return(0);
}
I don’t understand why the program doesn’t run and the message "Segmentation fault (core dumped)" is showing.
Here at br OS have dozens of answers to this problem, take a look here www.shorturl.at/flPU3
– Evilmaax
This helps you: https://answall.com/questions/52555/erro-segmentation-fault-core-dumped
– Rebeca Nonato
Why do you make one
for
traversingn
to display the final sentence?– Woss
Note that in C an array (which can be a string: a character array followed by the terminator character ' 0') the indices range from 0 to size-1. Your command
for
considers one more position. This is an error but not the cause of the reported problem that is in the last printf.– anonimo