Basic strings and removing newline character from end of char array
This commit is contained in:
parent
a99b168aff
commit
f158e68c55
@ -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;
|
||||||
|
|
||||||
|
|||||||
16
C/YT-BroCode/Strings/strings.c
Normal file
16
C/YT-BroCode/Strings/strings.c
Normal 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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user