using codeblocks
--------------------------------------------------------------------------------------------------------------
//program to copy a string to another using pointer passed to function// program title
#include <stdio.h> //header file
#include <string.h> // header file to handle string
void string_length(char [],char[]); // function prototype with character array
int main()
{
char string[50],string1[50]; // character string
puts("enter string1 and string2\n");
gets(string); //gets string
gets(string1);
string_length(string,string1); //calling of function with string as parameter
// here, string is passed as reference to formal parameter
return 0;
}
void string_length(char *strings,char *strings1)// this accepts string with address from main function
{
puts(strings);
puts(strings1);
printf("after copying\n");
strcpy(strings,strings1); // copies string
puts(strings); //displays string
}
//note: we can also use char string[] with void string_length in body line. It works.
//once you try.It runs.
//but we can not pass string as pointer in prototype.
// i.e. void string_length(char *[]);
--------------------------------------------------------------------------------------------------------------
//program to copy a string to another using pointer passed to function// program title
#include <stdio.h> //header file
#include <string.h> // header file to handle string
void string_length(char [],char[]); // function prototype with character array
int main()
{
char string[50],string1[50]; // character string
puts("enter string1 and string2\n");
gets(string); //gets string
gets(string1);
string_length(string,string1); //calling of function with string as parameter
// here, string is passed as reference to formal parameter
return 0;
}
void string_length(char *strings,char *strings1)// this accepts string with address from main function
{
puts(strings);
puts(strings1);
printf("after copying\n");
strcpy(strings,strings1); // copies string
puts(strings); //displays string
}
//note: we can also use char string[] with void string_length in body line. It works.
//once you try.It runs.
//but we can not pass string as pointer in prototype.
// i.e. void string_length(char *[]);
--------------------------------------------------------------------------------------------
using turboc++
------------------------------------------------------------------------------------------
//program to copy a string to another using pointer passed to function// program title
#include <stdio.h> //header file
#include <string.h> // header file to handle string
#include<conio.h>
void string_length(char [],char[]); // function prototype with character array
int main()
{
char string[50],string1[50]; // character string
puts("enter string1 and string2\n");
gets(string); //gets string
gets(string1);
string_length(string,string1); //calling of function with string as parameter
// here, string is passed as reference to formal parameter
getch();
return 0;
}
void string_length(char *strings,char *strings1)// this accepts string with address from main function
{
puts(strings);
puts(strings1);
printf("after copying\n");
strcpy(strings,strings1); // copies string
puts(strings); //displays string
}
//note: we can also use char string[] with void string_length in body line. It works.
//once you try.It runs.
//but we can not pass string as pointer in prototype.
// i.e. void string_length(char *[]);
No comments:
Post a Comment