Move the ask name code into its own function and file

This commit is contained in:
DeOwl committed 2026-09-09 16:47:55 +03:00
1 parent c07b87f2c2
commit 6b91325623
3 files changed
+13 -6

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <string.h>
void askname(char *first, char *last)
{
printf("Enter your first name: ");
fgets(first, 255, stdin);
first[strlen(first)-1] = '\0'; /* remove the newline at the end */
printf("Now enter your last name: ");
gets(last); /* buffer overflow? what's that? */
}
+1
View File
@@ -0,0 +1 @@
void askname(char *first, char *last);
+2 -6
View File
@@ -1,13 +1,9 @@
#include <stdio.h>
#include <string.h>
#include "askname.h"
int main(int argc, char **argv)
{
char first[255], last[255];
printf("Enter your first name: ");
fgets(first, 255, stdin);
first[strlen(first)-1] = '\0'; /* remove the newline at the end */
printf("Now enter your last name: ");
gets(last); /* buffer overflow? what's that? */
askname(first, last);
printf("Hello, %s %s!\n", first, last);
return 0;
}