Write a function Split that takes as argument a C string (terminated with ‘ \\0
ID: 3837552 • Letter: W
Question
Write a function Split that takes as argument a C string (terminated with ‘’) that contains a single occurrence of the ‘@’ character. Your function should print the two substrings separated by ‘@’ on separate lines, using the “%s” format specifier for printf. (You may not print individual characters with putchar or “%c”.)
Here are two examples showing the function behavior:
void Split(char * s)
{
/* Add your code here */
Function Call
Output
Split("place@here");
place
here
Split("do@that");
do
that
Function Call
Output
Split("place@here");
place
here
Split("do@that");
do
that
Explanation / Answer
StringSplit.C :
____________
#include<stdio.h>
#include<conio.h>
void Split(char*);
int main()
{
char *str="";
clrscr();
printf("enter string: ");
scanf("%s",str);
Split(str);
getch();
return 0;
}
void Split(char *s) // function spliting the string
{
char s1[50]={''},s2[50]={''};
int flag=0,k=0;
for(;*s!='';s++){
if(*s=='@'){
flag = 1;
k = 0;
}
else if(flag==0)
s1[k++] = *s;
else
s2[k++] = *s;
}
printf(" %s ",s1);
printf("%s",s2);
}
Sample Input and Output :
_______________________
enter string:
place@here
place
here
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.