I have the code below. When I print out the data I assign to the character arrays in the struct it prints out a bunch of junk unless I add an extra character to the array and put "/0". The problem with this is later on I need to grab the birth day and month as an integer (4 bytes). Can anyone tell me how to make it print out the appropriate data? I need the char array to be the exact size in memory of the size of the data.
#include <stdio.h> #include <string.h> struct Info { char studentID[6]; char firstName[5]; char lastName[4]; char birthDay[2]; char birthMonth[2]; char birthYear[4]; }; void printFunction( struct Info studentInfo ); int main() { struct Info studentInfo = {"999999", "first", "last", "01", "07", "1993"}; void *baseptr; asm("movl %%ebp,%0;":"=r"(baseptr)); printf("The value of the basepointer main:\n"); printf("%p\n", baseptr); printf("%-15s %s \n", "Student ID:", studentInfo.studentID); printf("%-15s %s \n", "First Name:", studentInfo.firstName); printf("%-15s %s \n", "Last Name:", studentInfo.lastName); printf("%-15s %s \n", "Birth Day:", studentInfo.birthDay); printf("%-15s %s \n", "Birth Month:", studentInfo.birthMonth); printf("%-15s %s \n", "Birth Year:", studentInfo.birthYear); printFunction( studentInfo ); return 0; } void printFunction( struct Info studentInfo ) { printf("The value of basepointer printFunction is:\n"); int *baseptr; asm("movl %%ebp,%0;":"=r"(baseptr)); printf("%p\n", baseptr); printf("The value at basepointer address is:\n"); printf("%p\n", *baseptr); printf("%-25s %p \n", "Address of Student ID:", &studentInfo.studentID); printf("%-25s %p \n", "Address of First Name:", &studentInfo.firstName); printf("%-25s %p \n", "Address of Last Name:", &studentInfo.lastName); printf("%-25s %p \n", "Address of Birth Day:", &studentInfo.birthDay); printf("%-25s %p \n", "Address of Birth Month:", &studentInfo.birthMonth); printf("%-25s %p \n", "Address of Birth Year:", &studentInfo.birthYear); printf("%s %x \n", "The address of my birth day and month is at address: ", &studentInfo.birthDay ); printf("%s \n", "The integer value of my birth day and month is: "); }
NULterminator.NULterminator.NULterminator.NULterminator.NULterminator.&studentInfo.studentIDbe&studentInfo->studentIDorstudentInfo.studentID?