# need c++ source code



## hsr (Sep 19, 2008)

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


----------



## ThinkFree (Sep 19, 2008)

Don't ask for whole code here. Just tell where you are finding trouble.


----------



## hsr (Sep 19, 2008)

well the reversing part of course ! cannot get it right.


----------



## nvidia (Sep 19, 2008)

```
for(i=0;i<l;i++)
reverse_string[i]=actual_string[l-i-1]
```
Where l = length of the string.


----------



## hsr (Sep 19, 2008)

well it is for a whole string but i need per word maintaining the spaces :
eg: hari is bad
irah si dab


----------



## Sykora (Sep 19, 2008)

First post what code you have, and tell us where you're going wrong.


----------



## nvidia (Sep 19, 2008)

Greatest of N numbers:

```
//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);
```


----------



## hsr (Sep 19, 2008)

not working, the program just terminates


----------



## nvidia (Sep 19, 2008)

^^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..


----------



## hsr (Sep 19, 2008)

yes and assignes big for string length


----------



## dheeraj_kumar (Sep 19, 2008)

```
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.


----------

