added beginner c sources
[my-code/beginners.git] / length.c
diff --git a/length.c b/length.c
new file mode 100644 (file)
index 0000000..7abd55a
--- /dev/null
+++ b/length.c
@@ -0,0 +1,37 @@
+/*  Type something ... and I tell you it's length!   */
+#include <string.h>
+#include <stdio.h>
+
+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);
+}
+
+