Find
Longer Repeating Sequence
#include
#include
#include
void main()
{
char
s1[100], ar[10][20], ar1[10][20], new[10];
int
i, j = 0, k = 0, l, count = 0, flag = 0, n, temp, len[20];
clrscr();
printf("\nenter the string:");
scanf(" %[^\n]s", s1);
for
(i = 0;s1[i] != '\0';i++,j++)
{
if (s1[i] >= 33 && s1[i] <= 64)
i++;
if (s1[i] == ' ')
{
ar[k][j] = '\0';
k++;
i++;
j = 0;
}
ar[k][j] = s1[i];
}
ar[k][j] = '\0';
l = 0;
for
(i = 0;i <= k;i++)
{
for (j = i + 1;j <= k;j++)
{
if (strcmp(ar[i], ar[j]) == 0)
{
for (n = 0;n < l && l != 0; n++)
{
if (strcmp(ar[i], ar1[k])
== 0)
{
flag = 1;
break;
}
}
if (flag != 1)
{
strcpy(ar1[l], ar[i]);
len[l] = strlen(ar1[l]);
l++;
}
flag = 0;
break;
}
}
}
printf("\n");
for (i = 0;i < l;i++)
{
for (j = i + 1;j < l;j++)
{
if (len[i] < len[j])
{
temp = len[i];
strcpy(new, ar1[i]);
len[i] = len[j];
strcpy(ar1[i], ar1[j]);
len[j] = temp;
strcpy(ar1[j], new);
}
}
}
maxlen = len[0];
for
(i = 0;i < l;i++)
{
if (len[i] == maxlen)
printf("\nthe longer repeating sequence of the given string is:
%s", ar1[i]);
}
getch();
}
Output
enter the string: Welcome to C Programming
Class, Welcome Again to C Programming Class!
the longer repeating sequence of the given
string is: Programming
Replace all the Characters by Lowercase
#include
#include
#include
void main(int argc, char* argv[])
{
FILE *fp1;
int ch;
if ((fp1 = fopen(argv[1], "r+")) == NULL)
{
printf("\nfile cant be opened");
exit(0);
}
ch = fgetc(fp1);
while (ch != EOF)
{
if (ch >= 65 && ch <= 90)
{
fseek(fp1, -1L, 1);
fputc(ch + 32, fp1);
}
ch = fgetc(fp1);
}
getch();
}
OutputCHANDANA chanikya
rAVELLA
chandana chanikya
ravella
Count the Total Number of Words in the Sentence using Command Line Argument
#include
#include
int main(int argc, char *argv[])
{
int i = 0;
clrscr();
if (argc == 1)
{
printf("\n No sentence given on command line");
return;
}
else
{
printf("\nThe words in the sentence are:");
for (i = 1;i < argc;i++)
{
printf("\n%s", argv[i]);
}
printf("\n\nTotal number of words:");
printf(" %d", argc-1);
}
getch();
}
Output
The words in the sentence are:
Welcome
to
C
Class
Total number of words: 4
No sentence given on command line
No comments:
Post a Comment