Strings in C Part – 1

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for String 
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char name[20];   // String 
    int i=0;
    system("cls");
    printf("Enter your Name: ");
    //scanf("%s",name);   // not allowed space 
      gets(name);
      puts(name);
    //printf("%s",name);
    //  while(name[i]!='\0')
    //  {
    //       printf("%c",name[i]);
    //       i++;
    //  }

    return 0;
}

Program 2

// Program for String 
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char str[50];
    int len,i;
    system("cls");
    printf("Enter a String");
    gets(str); 
    puts(str);
    // using inbuild function 
    //   len=strlen(str);
    //   printf("Length of string is %d : ",len);
    len=0;
 // without using inbuild function 
      i=0;
      while(str[i]!='\0')
      {
           i++;
      }
      printf("Length of String is %d: ",i);
    return 0;
}

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *