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. 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; }