Click here to Skip to main content
15,911,891 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCreating a Cwnd larger than desktop resolution Pin
Member 42276043-Feb-09 8:55
Member 42276043-Feb-09 8:55 
AnswerRe: Creating a Cwnd larger than desktop resolution Pin
«_Superman_»3-Feb-09 18:27
professional«_Superman_»3-Feb-09 18:27 
QuestionLine Break For Rich Edit Controls Pin
ForNow3-Feb-09 6:29
ForNow3-Feb-09 6:29 
QuestionLine Number macros to use in output of Message Box? Pin
ldsdbomber3-Feb-09 5:44
ldsdbomber3-Feb-09 5:44 
AnswerRe: Line Number macros to use in output of Message Box? Pin
Stuart Dootson3-Feb-09 6:01
professionalStuart Dootson3-Feb-09 6:01 
QuestionSerial Interface Baud Rate higher than 115200 Pin
stebefbe3-Feb-09 5:31
stebefbe3-Feb-09 5:31 
AnswerRe: Serial Interface Baud Rate higher than 115200 Pin
Roger Stoltz3-Feb-09 5:51
Roger Stoltz3-Feb-09 5:51 
QuestionHelp on CString Pin
parth.p3-Feb-09 5:08
parth.p3-Feb-09 5:08 
Hi guys, I am working on C String and I'm having this weird error. here's the code

#include <iostream>
#include <cstring>
#include <fstream>
//#include <stdlib.h>

using namespace std;



//Function Declarations
void get_longest_word (char data[]);


int main()

{
	char * MyString;

	
    cout<<"--------------------------------------------------------------"<<endl;
    
    cout<<"\nTask 1:\n"<<endl;    
    ifstream taskonefile("CStringText.txt");
    if(! taskonefile.is_open())
    {
        cout<<"Cannot Open File!"<<endl;
        exit(1);
    }
    int charCount;
    taskonefile.seekg(0, ios::end);
    charCount = taskonefile.tellg();
    taskonefile.seekg(0, ios::beg);
    charCount++;
    MyString = new char[charCount];
	
    taskonefile.get(MyString,charCount);
    cout<<MyString<<endl;

    
    cout<<"\nTask 2:\n"<<endl;
	
    
    cout<<"Longest word in the above paragraph: ";
    get_longest_word(MyString);
	
	
    cout<<"\nTask 3:\n"<<endl;
	
	int l_num = 0;
	
	cout<<MyString<<endl;
	for(int i =0; i<=strlen(MyString); i++)
	{
		if (MyString[i]=='l' || MyString[i]=='L')
		{
            l_num++;
		}
	}
	cout << "Number of Ls" << l_num;
	
	
	//EXIT+++++++++++++++++++++++++++++++++++++++++++++++++++
    cin.get();
    return 0;
	
}

//FUNCTIONS================================================

//TASK 2 FUNCTION
void get_longest_word (char data[])
{
    char * token;
    char * longest_word = "a";
	
    token = strtok(data, " ,.-");
	
    
    while (token != NULL)
    {   
        if (strlen (token) >= strlen(longest_word))
        {
            longest_word = token;
        }
		
        token=strtok(NULL, " ,.-");
    }
    
    cout<<longest_word<<endl;
}   


</stdlib.h></fstream></cstring></iostream>


The problem is when I some to task 3 after calling void get_longest_word the content of MyString which is local to int main() becomes only the first character of the entire string...

I have no clue what is happening wrong!

- Stop thinking in terms of limitations and start thinking in terms of possibilities -


AnswerRe: Help on CString Pin
krmed3-Feb-09 6:13
krmed3-Feb-09 6:13 
GeneralRe: Help on CString Pin
parth.p3-Feb-09 6:26
parth.p3-Feb-09 6:26 
GeneralRe: Help on CString Pin
Cedric Moonen3-Feb-09 7:25
Cedric Moonen3-Feb-09 7:25 
GeneralRe: Help on CString Pin
parth.p3-Feb-09 7:28
parth.p3-Feb-09 7:28 
GeneralRe: Help on CString Pin
CPallini3-Feb-09 9:38
mveCPallini3-Feb-09 9:38 
QuestionAvoid use of page file Pin
RomTibi3-Feb-09 4:52
RomTibi3-Feb-09 4:52 
AnswerRe: Avoid use of page file Pin
Stuart Dootson3-Feb-09 5:58
professionalStuart Dootson3-Feb-09 5:58 
GeneralRe: Avoid use of page file Pin
RomTibi3-Feb-09 8:51
RomTibi3-Feb-09 8:51 
QuestionCan't reference COM type library in x64 visual studio? Pin
Will58013-Feb-09 4:14
Will58013-Feb-09 4:14 
AnswerRe: Can't reference COM type library in x64 visual studio? Pin
«_Superman_»3-Feb-09 18:42
professional«_Superman_»3-Feb-09 18:42 
GeneralRe: Can't reference COM type library in x64 visual studio? Pin
Will58015-Feb-09 1:10
Will58015-Feb-09 1:10 
Questionhelp needed for encoding / saving "*.raw" images. Pin
cool guy Tmk3-Feb-09 3:37
cool guy Tmk3-Feb-09 3:37 
AnswerRe: help needed for encoding / saving "*.raw" images. Pin
Stuart Dootson3-Feb-09 5:52
professionalStuart Dootson3-Feb-09 5:52 
AnswerRe: help needed for encoding / saving "*.raw" images. Pin
Saurabh.Garg3-Feb-09 16:34
Saurabh.Garg3-Feb-09 16:34 
AnswerRe: help needed for encoding / saving "*.raw" images. Pin
Hamid_RT3-Feb-09 20:59
Hamid_RT3-Feb-09 20:59 
QuestionEuler's Contant To The X Power Pin
little_missy3-Feb-09 2:11
little_missy3-Feb-09 2:11 
AnswerRe: Euler's Contant To The X Power Pin
toxcct3-Feb-09 2:34
toxcct3-Feb-09 2:34 

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.