Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with C Programming assignment
#25
That inner while loop should be changed to an if instead. The way you have it now, it keeps matching characters in shortstr with the same character in longstr, so iii gets matched with the i in peice.

Actually, there are a number of things wrong there...

Code:
for (i = 0; longstr[i]; i++) {
  if (shortstr[j] == '\0')
    break; // end of shortstr
  if (longstr[i] == shortstr[j])
    j++; // match against the next character
}

return (shortstr[j] == '\0') // true if all of shortstr was matched, false otherwise
Reply


Messages In This Thread
Need help with C Programming assignment - by Fiel - 2009-11-23, 09:18 PM
Need help with C Programming assignment - by Fiel - 2009-11-23, 09:22 PM
Need help with C Programming assignment - by Fiel - 2009-11-25, 08:13 AM
Need help with C Programming assignment - by Fiel - 2009-11-25, 11:51 AM
Need help with C Programming assignment - by Russt - 2009-11-26, 06:33 PM

Forum Jump:


Users browsing this thread: