Sorry... another post... I'm so sick of tired of doing my C programming assignment. When will I achieve the level of your programming skill....
Here is the programe, and fatal error on the while loop is there anything wrong with the program, or is there any simpler way to solve this....
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void insertsub (char str[]);
main()
{
char str[100];
printf ("Enter the String :");
fgets (str, sizeof str, stdin);
printf ("\n");
insertsub (str);
return 0;
}
void insertsub (char str[])
{
char substr[100], temp[100];
char *start, *end, *p, sp;
int i;
printf ("Enter the substring you want to insert: ");
fgets (substr, sizeof substr, stdin);
p = strchr(substr, '\n');
if (p) *p = '\0';
printf ("Enter the starting character in the string for the insertion: ");
scanf("%c", &sp);
end = strchr (str, '\0');
start = strchr(str, sp);
if (start)
{
printf ("String not Found !!!");
}
for (start, i=0; *start!='\0'; start++, i++)
{
start = &temp[i];
while (end != strchr(str, sp))
end--;
}
*(end + 1) = '\0';
strcat (str, substr);
strcat (str, temp);
printf ("The output of the string with sub string inscerted: %s ", str);
}