Edit I fixed it but now I have a slightly different problem... The code compiles but my output looks like this
"What is your name?Morgan
Hello Morgan! Nice to meet you!
The first character in your name is M
Your name is 6 chars long
I changed the first letter of your name to W
Hello Norgan! Nice to meet you!
The first character in your name is N
Your name is 6 chars long"
The W/N mix up is actually kind of funny but here is the code. * Also it seems to produce this output every time letting me think my random pickletter function failed.
Code:
GNU nano 1.3.12 File: person.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void changeFirstChar(char* name, char first);
void chopToFirst(char* name);
void greet(char* name);
char pickletter(void);
int main(){
char name[101];
printf("What is your name?");
scanf("%100s",name);
greet(name);
changeFirstChar(name, pickletter());
greet(name);
}
void greet(char* name){
printf("Hello %s! Nice to meet you!\n",name);
printf("The first character in your name is %c\n",name[0]);
printf("Your name is %d chars long\n",strlen(name));
}
void changeFirstChar(char* name, char first){
name[0] = first;
first = pickletter();
printf("I changed the first letter of your name to %c\n");
}
char pickletter(void){
char* letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int letterIndex = rand() % strlen(letters);
return letters[letterIndex];
}