Archive Pages Design$type=blogging

Write a Program in C to Copy a String to Another.

Here is a program in C to copy one string to another string using user defined function. Here two character arrays are defined then prompted...


Here is a program in C to copy one string to another string using user defined function. Here two character arrays are defined then prompted to enter the strings and copied to the first string using while() function.

Program in C to Copy a String to Another



Program in C to Copy a String to Another



Steps:
  1. At first  declare two strings str1 and str2 and integers m, i, flag and j under main function.
  2. Prompt message to enter the strings and allow to enter strings using gets() function.
  3. Prompt the message and allow to enter the index where you want to insert in the first string.
  4. Copy second string to the first string using while() function.
  5. Print the first string to the screen.



Code:

#include <stdio.h>
#include <conio.h>

void main()
{
char str1[20], str2[20];
int m,i,flag=0,j;

clrscr();

printf("Enter the 1st String");
gets(str1);
printf("Enter the 2nd String");
gets(str2);

printf("Enter the index after which you want to insert 2nd string in 1st :");
scanf("%d", &m);
i=0;

while (i<=m)
{
i++;
}
j=0;

while (str2[j]!='\0')
{
str1[i]=str2[j];
i++;
j++;
if (str1[i]=='\0')
flag=1;
}

if (flag==1)
str1[i]='\0';
printf("%s", str1); 
getch();




Related Posts:


تعليقات

الاسم

Artificial Intelligence(AI) Backlinking Basic IT Best List Blogging Tips C C# C++ Computer Architecture Computer Fundamental Computer Security Computer/IT Officer Exam CSS Data Mining and Warehousing Data Recovery Tools Data Structure Database Management System E-commerce E-government Internet & Web Designing IT Law IT Tips and Tricks IT Tutorials Java JavaScript Keyword Research Tools MIS Multiple Choice Question (MCQ) Networking Online Earning Online IT Jobs Operating System Oracle Forms and Reports Programming Guide Programming Language SEO Social Networking Sites Software Download Software Engineering System Analysis and Design Top List VB.Net
false
rtl
item
Max6: Write a Program in C to Copy a String to Another.
Write a Program in C to Copy a String to Another.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr91Z-6hcRsaKTESlPH0N8lO9zuSIQWeaGSWVe7I1LOr26cg7o0C3BTLbCXHt-C98P8KFZIZjhhz-LlZ-jP_zE5QvagwIzB1YzDbIH7Vkdv_VBJ6hu_dWtGJOTcvktzOTjUclQcchuLSc5/s1600/C-string-copy.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr91Z-6hcRsaKTESlPH0N8lO9zuSIQWeaGSWVe7I1LOr26cg7o0C3BTLbCXHt-C98P8KFZIZjhhz-LlZ-jP_zE5QvagwIzB1YzDbIH7Vkdv_VBJ6hu_dWtGJOTcvktzOTjUclQcchuLSc5/s72-c/C-string-copy.png
Max6
https://maxs29.blogspot.com/2014/07/write-program-in-c-to-copy-string-to.html
https://maxs29.blogspot.com/
http://maxs29.blogspot.com/
http://maxs29.blogspot.com/2014/07/write-program-in-c-to-copy-string-to.html
true
4303790511137642940
UTF-8
لم يتم العثور على اى مواضيع شاهد الكل اقرأ المزيد رد احذف الرد حذف بواسطة الرئيسية صفحات مواضيع شاهد الكل نوصى لك التسميات الارشيف بحث لم يتم العثور على ماتبحث عنه عودة للرئيسية الاحد الاثنين الثلاثاء الاربعاء الخميس الجمعة السبت الاحد الاثنين الثلاثاء الاربعاء الخميس الجمعة السبت يناير فبراير مارس ابريل مايو يونيو يوليو اغسطس سبتمبر اكتوبر نوفمبر ديسمبر يناير فبراير مارس ابريل مايو يونيو يوليو اغسطس سبتمبر اكتوبر نوفمبر ديسمبر just now 1 دقيقة مضت $$1$$ دقيقة مضت 1 hour ago $$1$$ ساعة مضت الامس $$1$$ يوم مضى $$1$$ اسبوع مضى اكثر من 5 اسابيع مضت