Professional Documents
Culture Documents
VJWTSS11190015
1.Write a c program to read a string and print the number of words and
characters in the string.
Program:
/*
*File: c1.c
*Author: U.Ravikiran
*Creator Date: 14/12/2019
*Requirement: #include<stdio.h>
*Description: To read a string and print the number of words and characters in the
string.
*/
#include<stdio.h>
#include<string.h>
int main()
{
char str[100],*p;
int i,word=0,ch=0;
printf("Enter the string:");
gets(str);
p=str;
for(i=0;*p!='\0';i++,p++)
{
if(*p==' ')
{
word++;
ch++;
}
else
ch++;
}
printf("Number of words:%d\n",word+1);
printf("Number of characters:%d\n",ch);
}
Output:
#include<stdio.h>
#include<string.h>
int main()
{
char *p,a[30],b[20];
printf("Enter any string:");
gets(a);
printf("Enter the substring to be searched:");
gets(b);
if(p=strstr(a,b))
{
printf("String found in the main string\n");
}
else
{
printf("String not found in the main string\n");
}
}
Output:
Output:
Program:
/*
*File: c5.c
*Author: U.Ravikiran
*Creator Date: 14/12/2019
*Requirement: #include<stdio.h>
*Description: To store the list of the customer
*/
#include<stdio.h>
#include<stdlib.h>
struct cust
{
int cust_num;
char cust_name[50];
float cust_bill;
struct cust *n;
};
int main()
{
struct cust *st=NULL,*p,*f;
char ch='y';
for( ;ch!='n'; )
{
f=(struct cust*)malloc(sizeof(struct cust));
printf("Enter customer number\n");
scanf("%d",&f->cust_num);
printf("Enter customer name\n");
scanf("%s",f->cust_name);
printf("Enter customer bill amount\n");
scanf("%f",&f->cust_bill);
f->n=NULL;
if(st==NULL)
st=f;
else
{
for(p=st;p->n!=NULL;p=p->n);
p->n=f;
}
getchar();
printf("Enter y to continue n to exit :-");
scanf("%c",&ch);
}
for(p=st;p!=NULL;p=p->n)
{
Program:
/*
*File: c8.c
*Author: U.Ravikiran
*Creator Date: 14/12/2019
*Requirement: #include<stdio.h>
*Description: To search a customer in the given list.
*/
#include<stdio.h>
#include<stdlib.h>
struct cust
{
int cust_num;
char cust_name[50];
float cust_bill;
struct cust *n;
};
int main()
{
struct cust *st=NULL,*p,*f;
char ch='y';
for( ;ch!='n'; )
{
f=(struct cust*)malloc(sizeof(struct cust));
printf("Enter customer number\n");
scanf("%d",&f->cust_num);
printf("Enter customer name\n");
scanf("%s",f->cust_name);
printf("Enter customer bill amount\n");
scanf("%f",&f->cust_bill);
f->n=NULL;
if(st==NULL)
st=f;
else
{
for(p=st;p->n!=NULL;p=p->n);
p->n=f;
}
getchar();
printf("Enter y to continue n to exit:-");
scanf("%c",&ch);
}
for(p=st;p!=NULL;p=p->n)
{