C Programming :: Structures, Unions, Enums
-
If the following structure is written to a file using fwrite(), can fread() read it back successfully?
struct emp { char *n; int age; }; struct emp e={"Freshergate}; FILE *fp; fwrite(&e, sizeof(e), 1, fp);
-
Will the following code work?
#include
struct emp { int len; char name[1]; }; int main() { char newname[] = "Rahul"; struct emp *p = (struct emp *) malloc(sizeof(struct emp) -1 + strlen(newname)+1); p->len = strlen(newname); strcpy(p -> name, newname); printf("%d %s\n", p->len, p->name); return 0; }