Click here to Skip to main content
15,902,198 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: finding longest word Pin
Richard MacCutchan10-Jan-18 22:46
mveRichard MacCutchan10-Jan-18 22:46 
GeneralRe: finding longest word Pin
Anonygeeker10-Jan-18 23:00
Anonygeeker10-Jan-18 23:00 
AnswerRe: finding longest word Pin
Jochen Arndt10-Jan-18 22:45
professionalJochen Arndt10-Jan-18 22:45 
AnswerRe: finding longest word Pin
CPallini10-Jan-18 23:31
mveCPallini10-Jan-18 23:31 
QuestionCString to CByteArray Pin
_Flaviu9-Jan-18 0:16
_Flaviu9-Jan-18 0:16 
AnswerRe: CString to CByteArray Pin
Jochen Arndt9-Jan-18 1:11
professionalJochen Arndt9-Jan-18 1:11 
AnswerRe: CString to CByteArray Pin
Victor Nijegorodov9-Jan-18 1:15
Victor Nijegorodov9-Jan-18 1:15 
AnswerRe: CString to CByteArray Pin
leon de boer9-Jan-18 2:26
leon de boer9-Jan-18 2:26 
GeneralRe: CString to CByteArray Pin
_Flaviu10-Jan-18 0:21
_Flaviu10-Jan-18 0:21 
QuestionMultiThread Question Pin
ForNow8-Jan-18 2:03
ForNow8-Jan-18 2:03 
AnswerRe: MultiThread Question Pin
Jochen Arndt8-Jan-18 2:28
professionalJochen Arndt8-Jan-18 2:28 
GeneralRe: MultiThread Question Pin
ForNow8-Jan-18 2:41
ForNow8-Jan-18 2:41 
GeneralRe: MultiThread Question Pin
Jochen Arndt8-Jan-18 3:00
professionalJochen Arndt8-Jan-18 3:00 
GeneralRe: MultiThread Question Pin
ForNow8-Jan-18 3:03
ForNow8-Jan-18 3:03 
Questionarray and pointer Pin
Anonygeeker7-Jan-18 18:02
Anonygeeker7-Jan-18 18:02 
AnswerRe: array and pointer Pin
Rick York7-Jan-18 18:56
mveRick York7-Jan-18 18:56 
AnswerRe: array and pointer Pin
CPallini7-Jan-18 21:44
mveCPallini7-Jan-18 21:44 
AnswerRe: array and pointer Pin
cao_aba39-Jan-18 15:55
cao_aba39-Jan-18 15:55 
GeneralRe: array and pointer Pin
Richard MacCutchan9-Jan-18 22:26
mveRichard MacCutchan9-Jan-18 22:26 
QuestionWhat am I doing wrong defining single bit? Pin
Vaclav_7-Jan-18 12:36
Vaclav_7-Jan-18 12:36 
AnswerRe: What am I doing wrong defining single bit? Pin
leon de boer7-Jan-18 15:23
leon de boer7-Jan-18 15:23 
GeneralRe: What am I doing wrong defining single bit? Pin
Vaclav_8-Jan-18 5:37
Vaclav_8-Jan-18 5:37 
QuestionC program to reverse the order of the words entered. Pin
Tarun Jha7-Jan-18 6:45
Tarun Jha7-Jan-18 6:45 
for ex,
input: My name is Bay Max.
output: Max Bay is name My.

below is my code, but its too long and messy. How do i make it more concise and readable?
Any alternative would be appreciated.

C++
#include <stdio.h>
#include <string.h>

#define EOL '\n'
#define MAX_SIZE 100

int main(){

    char text[MAX_SIZE], back[MAX_SIZE], temp[MAX_SIZE];
    int count, i, mark[50];

	//reading the text
    for(count=0; (text[count] = getc(stdin))!= EOL; ++count){
        mark[count]=0;
    }
    text[count] = '\0';

	//reversing the text
    for(i = count-1; i>=0; --i){
        back[(count-1)-i] = text[i];
    }
    back[count] = '\0';

	//noting the frequencies of the occurences of space
	for(i=count-1; i>=0; --i){
		if(back[i]== ' '){
            mark[i] = i;
        }
	}

	//irr-reversing each words at their respective place
    int j, k=0, l=0;
    for(i=0; i<count-1; i++){
        if(mark[i] != 0){
            for(j=mark[i]-1; j>=k; j--){
                temp[l] = back[j];					//it reverse the words btw two space entries
                l++;
            }           
            temp[mark[i]] = ' ';
            l= l+1;
            k = mark[i]+1;
        }
    }
    for(i=count-1; i>=k; i--){
    	temp[l] = back[i];				//it reverse the word after the last space entry. 
    	l++;
	}
    
    //printing the string.
    printf("\n%s", temp);
    return 0;
}



Thank you.
GeneralRe: C program to reverse the order of the words entered. Pin
PIEBALDconsult7-Jan-18 7:01
mvePIEBALDconsult7-Jan-18 7:01 
SuggestionRe: C program to reverse the order of the words entered. Pin
David Crow7-Jan-18 15:50
David Crow7-Jan-18 15:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.