Write a program that does not use the inbuilt string function to concatenate two strings 10m Jun2009

By | April 23, 2016

Write a program that does not use the inbuilt string function to perform the following: 10m Jun2009

(ii) To concatenate two strings

Code:-

#include<stdio.h>
void main()
{
void str_concat(char*,char*,char*);
char Str1[50],Str2[50],Str3[100];
clrscr();
printf(“\nENTER FIRST STRING TO CONCATE : “);
scanf(“%s”,&Str1);
printf(“\nENTER SECOND STRING TO CONCATE : “);
scanf(“%s”,&Str2);
str_concat(Str1,Str2,Str3);
printf(“\nSTR1 IS : %s”,Str1);
printf(“\nSTR2 IS : %s”,Str2);
printf(“\nSTR3 IS : %s”,Str3);
getch();
}
void str_concat(char *STR1,char *STR2,char *STR3)
{
while(*STR1)
{
*STR3=*STR1;
STR1++;
STR3++;
}

while(*STR2)
{
*STR3=*STR2;
STR2++;
STR3++;
}
*STR3=*STR1;

}

#include<stdio.h>
void main()
{
void str_concat(char*,char*,char*);
char Str1[50],Str2[50],Str3[100];
clrscr();
printf("\nENTER FIRST STRING TO CONCATE : ");
scanf("%s",&Str1);
printf("\nENTER SECOND STRING TO CONCATE : ");
scanf("%s",&Str2);
str_concat(Str1,Str2,Str3);
printf("\nSTR1 IS : %s",Str1);
printf("\nSTR2 IS : %s",Str2);
printf("\nSTR3 IS : %s",Str3);
getch();
}
void str_concat(char *STR1,char *STR2,char *STR3)
{
while(*STR1)
{
*STR3=*STR1;
STR1++;
STR3++;
}
while(*STR2)
{
*STR3=*STR2;
STR2++;
STR3++;
}
*STR3=*STR1;
}

Screen Shots:

C_program_String_Concate

C_program_String_Concate_Output

 

 

 

(a) Develop an algorithm, draw the corresponding flow chart and write a program in’C’ to print the sum of the digits of a three digit number. 10

Solved program can be found on this link http://cssimplified.com/c-programming/write-an-algorithm-and-draw-a-corresponding-flow-chart-to-print-the-sum-of-the-digits-of-a-given-number

 

(b) Write a program that does not use the inbuilt string function to perform the following: 10

 (i) To compare two strings

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-program-that-does-not-use-the-inbuilt-string-functions-to-perform-the-following-10m-jun2006

 

(c) Write ‘C’ programs to read a string and check whether it is palindrome or not. 10

Solved program can be found on this link http://cssimplified.com/c-programming/design-an-algorithm-draw-a-corresponding-flowchart-and-write-a-c-program-to-check-whether-a-given-string-is-a-palindrome-or-not-10m-jun2006

 

(d) Write the output of the following program: 5

main( )

{

Int x=2, y=3, S1, S2;

S1= x+ (+ +y);

S2= + + x + y + +;

Printf (“%d%d%d%d\n”S1, S2, x, y);

}

 

Output: 6 7 3 5

 

(e) Differentiate between structure and union. 5

Solved program can be found on this link http://cssimplified.com/c-programming/what-are-the-differences-between-structure-and-union-give-example-of-usage-of-the-union-8m-jun2008

 

2. (a) Summarize the purpose of the format strings (like %s, %d, %c) that are corrunonly used within the printf function, with an example for each. 10

Solved program can be found on this link http://cssimplified.com/c-programming/summarize-the-purpose-of-the-format-strings-like-s-d-c-that-are-commonly-used-within-the-printf-function-with-an-example-for-each-10m-jun2006