X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fbeginners.git;a=blobdiff_plain;f=length.c;fp=length.c;h=7abd55a5188ff71141f1b6221ff034f848703347;hp=0000000000000000000000000000000000000000;hb=62e4aa7ef68064df6c9c2d72734e21af2b672758;hpb=2473d40268a211cffc6bfbd8a19e66fce838c236 diff --git a/length.c b/length.c new file mode 100644 index 0000000..7abd55a --- /dev/null +++ b/length.c @@ -0,0 +1,37 @@ +/* Type something ... and I tell you it's length! */ +#include +#include + +char first[100]; /* string for firstname */ +char last[100]; /* etc. */ +char full[200]; /* string for the full name */ +char line[4]; /* string for age */ +int age; /* variable for Age */ + +int main() +{ + printf(" -----------------------------------------------------------\n"); + printf("Yoh dude, ready to let me count...:\n"); + + printf("Enter first name: "); + fgets(first, sizeof(first), stdin); + first[strlen(first) - 1] = '\0'; + + printf("now the last name : "); + fgets(last, sizeof(last), stdin); + last[strlen(last) - 1] = '\0'; + + printf("...and your age: "); + fgets(line, sizeof(line), stdin); + sscanf(line ,"%d" ,&age); + + strcpy(full, first); + strcat(full, " "); + strcat(full, last); + + printf("%s got %d cHaRaCtErS man!\n", full, strlen(first) + strlen(last) - 2); /* -- \0 must not be counted -- */ + printf("...and you are %d years old!\n",age ); + return(0); +} + +