need c++ source code

Status
Not open for further replies.
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
 

nvidia

-----ATi-----
Code:
for(i=0;i<l;i++)
reverse_string[i]=actual_string[l-i-1]
Where l = length of the string.
 
OP
H

hsr

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

nvidia

-----ATi-----
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);
 

nvidia

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

dheeraj_kumar

Legen-wait for it-dary!
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.
 
Status
Not open for further replies.
Top Bottom