From 13b44fd9c77cda7b33880c000f744d8f5fa07598 Mon Sep 17 00:00:00 2001 From: Satyajit Mahunta <56647750+SatyajitMahunta@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:10:33 +0530 Subject: [PATCH 1/2] Create README.md Readme file created. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..13d04c9 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Here are some simple programs for beginners. + +1. Simple Hello World Program. +2. Frequency of a character in a string. +3. How to find the length of a string +4. Program to read a line from a file. From 8514300182981c97ade7a4f7ddd7af85eb78f684 Mon Sep 17 00:00:00 2001 From: Satyajit Mahunta <56647750+SatyajitMahunta@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:23:14 +0530 Subject: [PATCH 2/2] Update length of a string strlen used for finding string length. --- length of a string | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/length of a string b/length of a string index 810e5cd..2f36235 100644 --- a/length of a string +++ b/length of a string @@ -1,11 +1,15 @@ #include +#include int main() { - char s[1000]; - int i; - printf("Enter a string: "); - scanf("%s", s) - for(i = 0; s[i] != '\0'; ++i) - printf("Length of string: %d", i); - + char a[100]; + int length; + printf("Enter a string to calculate its length\n"); + gets(a); + // strlen function to find the length of the string + length = strlen(a); + + printf("Length of the string = %d\n", length); + + return 0; }