Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arrays, Strings, Searching and Sorting Module 3: Sudarsanan D

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

ARRAYS, STRINGS,SEARCHING AND SORTING MODULE 3 Sudarsanan D

GETS AND PUTS FUNCTION:


You can use gets() function to read a line of string. And, you can use puts() to
display the string.

#include <stdio.h>
int main()
{
char name[30];
printf("Enter name: ");
gets(name); // read string
printf("Name: ");
puts(name); // display string
return 0;
}

OUTPUT:

Enter name: Tom Hanks


Name: Tom Hanks

Write a program to copy one string into another and count the number of
characters copied.
copied.
#include<stdio.h>
void main()
{
char string1[80],string2[80];
int i;
printf("Enter the string\n");
scanf("%s",string2);
for(i=0; string2[i]!='\0'; i++)
string1[i]=string2[i];
string1[i]='\0';
printf("\n");
printf("copied string is:");
printf("%s\n",string1);
printf("Number of characters = %d\n",i);
}

output:

Dept. of ISE, Sapthagiri College of Engg. 27

You might also like