this is just a small question on NULL. In the snippet below, why doesn't the do-while loop repeat when I don't enter anything for the string?
#include <stdio.h>
#include <string.h>
#include <cs50.h>
int main(int argc, char* argv[])
{
string name;
do
{
printf("Enter your name: ");
name = GetString();
}while(name == NULL);
printf("%s\n", name);
}
EDIT: I checked if GetString() returns null by inserting the following into the do-while loop:
if (name == NULL) printf("Returned NULL");
The workaround was
do
{same content)while(*name == '\0')
Any now I can't even remember how the workaround worked, do strings automatically get a newline inserted at the beginning when they're initialized?
Damn.
GetString
actually returnsNULL
.NULL
? you may edit your original post!