-
Sorry yall by nomeans did I mean to ignore your posts, that would be like a 4th grader telling the teacher he didnt need to listen to her, ok trying to change gets() to fgets(), I though it was used for reading from a file, shrug.
Code:
/* function defintion */
void DataReceive(WF *ptr_wld)
{
printf("Enter Room Description:\n");
fgets(ptr_wld->rdescp);
printf("Enter Room Name(YOU MUST ADD ~ TO THE END):\n");
fgets(ptr_wld->roomname);
printf("Enter Zone Number: Room Bivector: Sector Type: (A space between each one)\n");
scanf("%d %d %d\n", &ptr_wld->zone_num, &ptr_wld->room_biv, &ptr_wld->sect_type);
printf("Enter ~ (Nothing Else)\n");
fgets(ptr_wld->sqwigly);
printf("Enter Virtual Number:\n");
scanf("%d\n", &ptr_wld->v_num);
}
so the code to get ride of the \n char, does it go inside of my function?
and one more thing it says that to few arguments are passed through fgets().
i see fgets() is like this
fgets(char *s, int n, FILE *stream)
what should i put for the FILE *stream so it will read from stdin?
THanks agin for all your help
-
You're going to love this: stdin :)
-
The second parameter is the size of the buffer. You can put sizeof(pointer_in_first_argument_here).
Beware that sizeof only works on arrays, and not on pointers. If you pass a pointer to fgets, you have to pass the size of the buffer to the function which calls fgets.
-
Sorry to bother yall agin. when I try to use fgets(), when i put in the variable from my struct, into the function defention it says it is undefined, but I am using a pointer that points to the struct, so i dont understand it.
/* function defintion */
void DataReceive(WF *ptr_wld)
{
printf("Enter Room Description:\n");
fgets(rdescp, sizeof(ptr_wld), stdin);
-
Code:
void DataReceive(WF *ptr_wld)
{
printf("Enter Room Description:\n");
fgets(rdescp, sizeof(ptr_wld), stdin);
Where do you see rdescp? I don't see it anywhere.
Further, sizeof(ptr_wld) will likely return 4, but one thing is for sure - it will not return the size of the struct.
If you pass a single struct, then you need to dereference the pointer. After all, the size of T* is not the same as the size of T (which is why I always emphasize that T* is a type!).