Garbage printed with string after strcpy

Advertisements I am a beginner in C and I am trying to copy a string inside another one. I have the following code: #include <stdio.h> #include <string.h> typedef struct { float mort_2009, mort_2015, indices; char estado[]; } Mortalidade; void defineEstados ( Mortalidade *e, char estado[], float mort_2009, float mort_2015, int posix) { strcpy(e[posix].estado, estado); e[posix].mort_2009… Read More Garbage printed with string after strcpy

Garbage when converting character to string using concatenation

Advertisements I am converting a character to a string by concatenating it with an empty string (""). But it results in undefined behaviour or garbage characters in the resultant string. Why so? char c = ‘a’; string s = ""+c; cout<<s<<" "<<s.size()<<"\n"; >Solution : Let’s look at your snippet, one statement or a line at… Read More Garbage when converting character to string using concatenation

Is it possible to "create" garbage memory data in one C program, and then later read in that same data in from another C program?

Advertisements I would like to know if it is possible to in the first C program: Allocate and declare an int to the value of 5 in memory Print out the address of the variable (eg: 0x7ffee6a98ad8) Terminate And then in a second C program, after the first has completely finished executing: Read in the… Read More Is it possible to "create" garbage memory data in one C program, and then later read in that same data in from another C program?