Basic strings and removing newline character from end of char array

This commit is contained in:
ganome 2025-05-05 14:30:01 -06:00
parent a99b168aff
commit f158e68c55
Signed by untrusted user who does not match committer: Ganome
GPG Key ID: 944DE53336D81B83
2 changed files with 17 additions and 1 deletions

View File

@ -2,7 +2,7 @@
int main () { int main () {
printf("Hello World!\nFrom the C Programming Language\n"); printf("\v\v\v\v\v\v\v\v\t\tHello World!\n\tFrom the C Programming Language\n");
return 0; return 0;

View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <string.h>
int main() {
/* Strings are character arrays */
char name[100];
printf("\n\n\tPlease enter your name: \n");
fgets(name, 100, stdin);
name[strlen(name)-1] = '\0'; // This removes the newline character at the end of 'name' variable
printf("\n\nHello %s!\n\n", name);
return 0;
}