Could someone walk me though how to string in c? #include <stdio.h> #include <st
ID: 674209 • Letter: C
Question
Could someone walk me though how to string in c?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char fname[20];
printf("Enter your first name: ");
scanf("%s", &fname);
// strlen() function used to calculate the length of the string
int len = strlen(fname);
printf("There are %d letters in your first name ", len);
// TODO: print each letter in a separate line
//TODO: print all letters in a single line but put a space between each letters
printWithSpaces(fname);
return 0;
}
/* Complete the following function */
/* Use proper return type and arguments */
printWithSpaces(){
}
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void printWithSpaces(char *);
int main(){
char fname[20];
printf("Enter your first name: ");
scanf("%s", &fname);
// strlen() function used to calculate the length of the string
int len = strlen(fname);
printf("There are %d letters in your first name ", len);
// TODO: print each letter in a separate line
//TODO: print all letters in a single line but put a space between each letters
printWithSpaces(fname);
return 0;
}
/* Complete the following function */
/* Use proper return type and arguments */
void printWithSpaces(char *fname){
int index=0;
while(fname[index] != '') {
printf("%c ", fname[index++]);
}
printf(" ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.