We were given sample problems for a programming competition, all of them seem pretty easy. But I cant get this to work, and can't figure out why..
Code:int main(int argc, char* argv[]) { char *strDef = new char[50]; //first string char *tmp; //string to hold temporary register int i; //varable to hold loop printf("Please enter a sentence and press <ENTER>: "); gets(strDef); char *strNew = new char[strlen(strDef)]; if(!strNew) //make sure its valid return 0; for(i=0;i<=strlen(strDef);i++){ //begin checking if(strDef[i]==' ') i++; else if(strDef[i] == strDef[i+1]){ //check if there are two letters in a row strcat(strNew,(char*)strDef[i]); i+=2; } else{ strcat(strNew,(char*)strDef[i]); //strNew+=strDef[i]; } } printf("Here is the formatted string: %s", strNew); return 1; }




Reply With Quote