c programming beginner (arrays) -
the question asks input sentence (up 20 characters). if part of input there contains word bad, replaced ---. example, input bad dog output: --- dog, example input: bade , output: ---e.
i able set array.
#include <stdio.h> main() { int c, i; int counts[20]; (i = 0; <= 19; i=i+1) { counts[i] = 0; } c = getchar(); while (c!= '\n') { if () } }
#include <stdio.h> #include <string.h> int main(){ char sentence[20+1]; char *p; scanf("%20[^\n]", sentence); if(null!=(p = strstr(sentence, "bad"))){//only once!,, memcpy(p, "---", 3); } printf("%s\n", sentence); return 0; }
Comments
Post a Comment