More Related Content Similar to C code #include stdio.h #include stdlib.h #include mat.pdf (20) More from ANANDSALESINDIA105 (20) C code #include stdio.h #include stdlib.h #include mat.pdf1. // C code
#include
#include
#include
#include
#include
#include
void sortInputstring(char*);
void main()
{
char input[100];
printf("Enter the string ");
scanf(" %[^ ]s", input);
sortInputstring(input);
}
void sortInputstring(char *str)
{
int i, j, k, ws = 0;
char p[50][100],temp[50];
char *c;
c=str;
for (i = 0;i < strlen(str);i++)
{
if ((str[i] == ' ')||(str[i] == ',')||(str[i] == '.'))
{
ws++;
}
}
for (i = 0, j = 0, k = 0;j < strlen(str);j++)
{
if ((str[j] == ' ')||(str[j] == 44)||(str[j] == 46))
{
p[i][k] = '0';
i++;
2. k = 0;
}
else
p[i][k++] = str[j];
}
for (i = 0;i 0))
{
strcpy(temp, p[i]);
strcpy(p[i], p[j]);
strcpy(p[j], temp);
}
}
}
printf(" Sorting the input string: ");
for (i = 0;i <= ws;i++)
{
printf(" %s ", p[i]);
}
}
/*
output:
Enter the string
things stuff otherstuff blarp
Sorting the input string:
blarp
otherstuff
stuff
things
*/
Solution
// C code
#include
3. #include
#include
#include
#include
#include
void sortInputstring(char*);
void main()
{
char input[100];
printf("Enter the string ");
scanf(" %[^ ]s", input);
sortInputstring(input);
}
void sortInputstring(char *str)
{
int i, j, k, ws = 0;
char p[50][100],temp[50];
char *c;
c=str;
for (i = 0;i < strlen(str);i++)
{
if ((str[i] == ' ')||(str[i] == ',')||(str[i] == '.'))
{
ws++;
}
}
for (i = 0, j = 0, k = 0;j < strlen(str);j++)
{
if ((str[j] == ' ')||(str[j] == 44)||(str[j] == 46))
{
p[i][k] = '0';
i++;
k = 0;
}
else
4. p[i][k++] = str[j];
}
for (i = 0;i 0))
{
strcpy(temp, p[i]);
strcpy(p[i], p[j]);
strcpy(p[j], temp);
}
}
}
printf(" Sorting the input string: ");
for (i = 0;i <= ws;i++)
{
printf(" %s ", p[i]);
}
}
/*
output:
Enter the string
things stuff otherstuff blarp
Sorting the input string:
blarp
otherstuff
stuff
things
*/