DIGIT-ARC read-only archive · snapshot: July 23, 2026

need c++ source code

11 posts · originally from https://geek.digit.in/community/threads/need-c-source-code.97989/

H
hsr Original post #1
Sep 19, 2008 at 6:55 AM
To reverse each word in a string without using functions.
eg: hari is bad
irah si dab

to find greatest on n numbers using arrays

thanks
T
Sep 19, 2008 at 10:20 AM
Don't ask for whole code here. Just tell where you are finding trouble.
H
hsr #3
Sep 19, 2008 at 6:00 PM
well the reversing part of course ! cannot get it right.
nvidia
nvidia #4
Sep 19, 2008 at 6:02 PM
Code:
for(i=0;i<l;i++)
reverse_string[i]=actual_string[l-i-1]
Where l = length of the string.
H
hsr #5
Sep 19, 2008 at 6:11 PM
well it is for a whole string but i need per word maintaining the spaces :
eg: hari is bad
irah si dab
Sykora
Sykora #6
Sep 19, 2008 at 6:23 PM
First post what code you have, and tell us where you're going wrong.
nvidia
nvidia #7
Sep 19, 2008 at 9:32 PM
Greatest of N numbers:
Code:
//Input the numbers into an array
big=a[0];
for(i=1;i<n;i++)
{
 if(a[i]>big)
 big=a[i];
}
printf("%d",big);
H
hsr #8
Sep 19, 2008 at 9:43 PM
not working, the program just terminates
nvidia
nvidia #9
Sep 19, 2008 at 9:44 PM
^^Thats not the entire program! Did you add codes to input the array before that?
I just typed in the main part of the program..
H
hsr #10
Sep 19, 2008 at 9:59 PM
yes and assignes big for string length
dheeraj_kumar
Sep 19, 2008 at 10:59 PM
Code:
int wordcount = 0, strcount = 0, revcount = 0, strposition = 0; // counters n stuff 
char string [100], word [10], rev [10]; // obvious

while (string[strcount] != '\0') // till end of string
{
 strposition = strcount; //save current position

 while (string[strcount] != ' ') // word has started
   word [wordcount++] = string [strcount++]; //move along the word, copying the entire word to buffer

 while (wordcount >= 0)
  rev [revcount++] = word [wordcount--]; //classic reversing the word loop

 while (revcount >= 0) // move back to where the word started(we saved the position remember?)
  string [strposition++] = rev [revcount--]; // copy the reversed word to the place, overwriting word
}

Untested, but should work. Done with arrays, change it a bit to pointers for more flexibility.