Hi,
i would like your help in a program.
Code:
#include <stdio.h>
#include <string.h>
char s[1000];
int i,j,r,k,l;
int counter_aA (m)
{
k=0;
for(i=0; i<m; i++)
{
if (s[i]=='a'||s[i]=='A')
k++;
}
return k;
}
int counter_zZ (m)
{
l=0;
for(i=0; i<m; i++)
{
if (s[i]=='z'||s[i]=='Z')
l++;
}
return l;
}
int main()
{
printf("Enter Text Line and press ENTER :");
gets(s);
r=strlen(s);
printf("\n\n\n\nThe text is: ");
puts(s);
printf("\nThe number of aA is : %d\n",counter_aA(r));
printf("The number of zZ is : %d\n",counter_zZ(r));
if (k>l)
{
for(i=0; i<strlen(s); i++)
{
if (s[i]=='a')
s[i]='z';
if (s[i]=='A')
s[i]='Z';
}
printf("\n\n\n\nThe modified text is: ");
puts(s);
printf("\nThe NEW number of aA is : %d\n",counter_aA(r));
printf("The NEW number of zZ is : %d\n",counter_zZ(r));
}
else
if (k<l)
{
for(i=0; i<strlen(s); i++)
{
if (s[i]=='z')
s[i]='a';
if (s[i]=='Z')
s[i]='A';
}
printf("\n\n\nThe modified text is: ");
puts(s);
printf("\nThe NEW number of aA is : %d\n",counter_aA(r));
printf("The NEW number of zZ is : %d\n",counter_zZ(r));
}
else
{
if (k==l)
{
for(i=0; i<(strlen(s)/2); i++)
{
if (s[i]=='a')
s[i]='z';
if (s[i]=='A')
s[i]='A';
}
j=(strlen(s)-1);
while(j>(strlen(s)/2))
{
if (s[j]=='z')
s[j]='a';
else
if (s[j]=='Z')
s[j]='A';
j=j-1;
}
printf("\n\n\nThe modified text is: ");
puts(s);
printf("\nThe NEW number of aA is : %d\n",counter_aA(r));
printf("The NEW number of zZ is : %d\n",counter_zZ(r));
}
}
}
the problem asks to enter a text line an first print it then count both 'a'and'A' and 'z' and 'Z'of that line
--if the number of 'a'and'A' is > than 'z' and 'Z' replace 'a' with 'z' and 'A'with 'Z'
print the new line and count the new aA and zZ and vise versa.
--if the number of 'a'and'A' is equal(=) to 'z' and 'Z', replace 'a' with 'z' and 'A'with 'Z' until the middle of the sentence and from the end of the sentence to the middle(middle char is included) replace the 'z','Z' with 'a','A'.
Print the new sentence and the new number of 'a','A' and 'z','Z'
my code seems correct but i m told to use char*gets(char*s) instead of gets() but i don't know how.
Could you please help me ?
Thanx in advance...