I am trying to write a program that reads a string and shortens it if the letters are in a row. For instance abcdghigjhkhdf becomes a-dg-igkhkhdf. I want that it erases the ;etters it erases but it is not working. HEre is my code:
#include <stdio.h>
#define MAXSTRING 100
void main()
{
char str[MAXSTRING]={0};
printf("Please input a string of letters without a space or numbers.");
scanf_s("%s", &str);
convertString(str);
}
void convertString(char string[])
{
int i=0;
char startOfNewConinuation=0;
while (string[i]!= 0)
{
if (string[i]!= '-')
startOfNewConinuation=string[i];
if ((string[i+1]=string[i]+1) && (startOfNewConinuation=string[i]))
string[i+1]='-';
else
string[i]='';
i++;
}
printf("\nThe new string is %s",string);
}