I want to get info of someone in the getInfo function.
If I print the name when I'm IN the getInfo function, it prints it out correctly, but after that in the main it leaves some random characters.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* getLine(){
char *line = malloc(256);
fgets(line, 256, stdin);
if ((strlen(line) > 0) && (line[strlen (line) - 1] == '\n'))
line[strlen (line) - 1] = '\0';
return line;
}
void getInfo(char* name,char* place,char* days[]){
printf("Type in your name:\n");
name = getLine();
printf("%s",name); // <---- THIS PRINTS OUT CORRECTLY
}
int main( int argc, const char* argv[] )
{
char* name = (char*)malloc(100*sizeof(char));
char* place = (char*)malloc(100*sizeof(char));
char* days[5];
getInfo(name,place,days);
printf("%s\n",name); // <----- THIS LEAVES SOME CHARACTERS
}
OUTPUT:
C:\Users\Felhasznalo\Desktop>a.exe
Type in your name:
Peter Smith
Peter Smith`\┴
These " `\┴ " characters are what I'm talking about. The first print in the function prints it well, but in the main it gives these ghost characters.
Why are these written out? Thanks.