The following program compiles but has gibberish data inside of it and doesn’t replace..
#include <stdio.h>
#include <string.h>
int main (void)
{
int i;
char string[100];
printf("Enter a string");
fgets(string, 100, stdin);
for (i=0; i<strlen(string);i++)
{
if (string[i]=='o')
{
string[i]='0';
}
}
printf("%c", string);
return 0;
}
Calculate strlen before loop
Use %s instead of %c
As suggested by Vallabh Patade you don’t need to calculate length: