i just start before few week to learn c in university
i have homework to send to the Thacher tomorrow and i stuck with problem and i don't find solution the quastion is that i need to get string and if 3 letter with ascii number one after one its need to be like this : if i get string : abc its need to beck a-c i just fix it and its work well now i need to fix if its 4 or 5 letter one agter one so if its 4 its should look like this get : abcd return a-d and if its 5 letter one after one its look like this abcde return a-e
hope you understend what i mean i really will be thenfual if some one can help me
this is the code i write until now :
and this is the input: dabcefLMNOpQrstuv567zyz
The final answer should look like this : da-cefL-OpQr-v567zyx
with my code its return da-cefL-NOpQr-tuv-67zyx
hope someone can help me ![Smile](https://cboard.cprogramming.com/images/smilies/smile.png)
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define SIZE 80
int change(char str[]);
int main()
{
char str[SIZE];
printf("Enter The String Please: \n");
scanf("%s",str);
printf("Your String is: %s\n",str);
change(str);
return 0;
}
int change(char str[])
{
int count=1;
int i;
int start;
int end;
int now=0;
for (i = 0; i <= strlen(str); i++)
{
if(((int)str[i]) == ((int)str[i+1]-1))
{
count++;
start = i;
end = i+1;
printf("The number of change1 is: %d\n", count);
printf("Your new String is: %s\n", str);
}
if(count == 5)
{
int k;
for(k=i; str[k] != '\0';k++)
{ str[k] = str[k+2];
printf("countrtttttt %d\n",count);
printf("Your new String is: %s\n",str);
k--;
}
printf("The number of change5 is: %d\n", count);
printf("Your new String is: %s\n", str);
}
if(count == 4 )
{ int k;
for(k=i; str[k] != '\0';k++)
{ str[end] = str[k+1];
printf("countrtttttt %d\n",count);
printf("Your new String is: %s\n",str);
k--;
}
printf("The number of change5 is: %d\n", count);
printf("Your new String is: %s\n", str);
}
if(count == 3)
{
now=(start+end)/2;
str[now] = '-';
count =0;
printf("The number of change is: %d\n", count);
printf("Your new String is: %s\n", str);
}
}
printf("Your new String is: %s\n", str);
printf("Str look like this: da-cefL-OpQr-v567zyx \n");
printf("The number of change is: %d\n", count);
return 0;
}