Commits

Max Horn  committed dfeb90e

Remove trailing newlines from username

  • Participants
  • Parent commits b116272

Comments (0)

Files changed (1)

 #include "stdio.h"
 #include "stdlib.h"
+#include "string.h"
 
 int main(int argc, char **argv) {
 	char name[256];
+	int n;
 	printf("Hello, world!\n");
 	printf("Hello, universe!\n");
 	printf("Please enter your name: ");
 	fgets(name, sizeof(name), stdin);
+	n = strlen(name);
+	if (n > 0 && name[n-1] == '\n')
+		name[n-1] = 0;
 	printf("Hello, %s!\n", name);
 	return 0;
 }