Click here to Skip to main content
15,887,325 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSet background color of Menu. Pin
Le@rner29-Jan-10 20:17
Le@rner29-Jan-10 20:17 
AnswerRe: Set background color of Menu. Pin
LunaticFringe30-Jan-10 1:47
LunaticFringe30-Jan-10 1:47 
Questionchar* returns garbage value Pin
Anu_Bala29-Jan-10 19:10
Anu_Bala29-Jan-10 19:10 
AnswerRe: char* returns garbage value Pin
Richard MacCutchan29-Jan-10 22:23
mveRichard MacCutchan29-Jan-10 22:23 
AnswerRe: char* returns garbage value Pin
«_Superman_»30-Jan-10 20:28
professional«_Superman_»30-Jan-10 20:28 
Questionextracting data from .TXT file Pin
benjamin yap29-Jan-10 17:20
benjamin yap29-Jan-10 17:20 
AnswerRe: extracting data from .TXT file Pin
Richard MacCutchan29-Jan-10 22:19
mveRichard MacCutchan29-Jan-10 22:19 
AnswerRe: extracting data from .TXT file PinPopular
enhzflep30-Jan-10 7:02
enhzflep30-Jan-10 7:02 
My immediate approach would be to:

(a) Scan for and replace all comas with nothing. I.e "," --> ""
(b) Scan for the text ixic">
(c) if string not found, then exit loop - jump to (g)
(d) Advance the returned pointer by the length of the search string (6 bytes)
(e) Do a scanf, asking for a float
(f) Return to (b)
(g) ...

Perhaps a little something like this?

#include <stdlib.h>
#include<stdio.h>
#include<string.h>
#include <string>

using namespace std;

string& str_replace(const string &search, const string &replace, string &subject)
{
    string buffer;

    int sealeng = search.length();
    int strleng = subject.length();

    if (sealeng==0)
        return subject;//no change

    for(int i=0, j=0; i<strleng; j=0 )
    {
        while (i+j<strleng && j<sealeng && subject[i+j]==search[j])
            j++;
        if (j==sealeng)//found 'search'
        {
            buffer.append(replace);
            i+=sealeng;
        }
        else
        {
            buffer.append( &subject[i++], 1);
        }
    }
    subject = buffer;
    return subject;
}


int main()
{
    FILE *fp;
    char *htmlStr, *tmp, *filename="infile.html";
//    char *findMe = "ixic\">";
    char *pos1, *pos2, *pos3;
    float retrievedNum;
    long fileSize;
    string findMe = "ixic\">";

    fp = fopen(filename, "r+b");
    fseek(fp, 0, SEEK_END);
    fileSize = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    htmlStr = new char[fileSize+1];
    htmlStr[fileSize] = 0;
    fread(htmlStr, sizeof(char), fileSize, fp);
    string tmpS = htmlStr;

    string find = ",";
    string replace = "";

    tmpS = str_replace(find, replace, tmpS);

    printf("%s\n\n", tmpS.c_str() );
    fclose(fp);
    strcpy(htmlStr, tmpS.c_str() );
    pos1 = htmlStr;

    while (pos1 = strstr(pos1, findMe.c_str()))
    {
            pos1 += strlen(findMe.c_str());
            sscanf(pos1, "%f", &retrievedNum);
            printf("Retrieved: %f\n", retrievedNum);
    }

    delete htmlStr;
}


Yeah, the code's not winning any beauty pageants. Blush | :O
AnswerRe: extracting data from .TXT file Pin
Moak30-Jan-10 13:11
Moak30-Jan-10 13:11 
QuestionAutoRestart + Execute Useer Code Pin
Bram van Kampen29-Jan-10 14:24
Bram van Kampen29-Jan-10 14:24 
QuestionAccessing vars in class created with new Pin
al250029-Jan-10 12:48
al250029-Jan-10 12:48 
AnswerRe: Accessing vars in class created with new Pin
Avi Berger29-Jan-10 14:00
Avi Berger29-Jan-10 14:00 
GeneralRe: Accessing vars in class created with new Pin
al250029-Jan-10 14:23
al250029-Jan-10 14:23 
GeneralRe: Accessing vars in class created with new Pin
al250029-Jan-10 15:55
al250029-Jan-10 15:55 
GeneralRe: Accessing vars in class created with new Pin
Avi Berger1-Feb-10 11:22
Avi Berger1-Feb-10 11:22 
AnswerRe: Accessing vars in class created with new Pin
Richard MacCutchan30-Jan-10 1:12
mveRichard MacCutchan30-Jan-10 1:12 
GeneralRe: Accessing vars in class created with new Pin
al250030-Jan-10 8:04
al250030-Jan-10 8:04 
QuestionRe: Accessing vars in class created with new Pin
David Crow30-Jan-10 12:52
David Crow30-Jan-10 12:52 
AnswerRe: Accessing vars in class created with new Pin
al25001-Feb-10 11:47
al25001-Feb-10 11:47 
QuestionHow to assign directory rights programmatically? Pin
Chintan29-Jan-10 10:38
Chintan29-Jan-10 10:38 
QuestionWindows Shell Replacement Pin
Code-o-mat29-Jan-10 9:22
Code-o-mat29-Jan-10 9:22 
AnswerRe: Windows Shell Replacement Pin
Richard MacCutchan29-Jan-10 9:49
mveRichard MacCutchan29-Jan-10 9:49 
GeneralRe: Windows Shell Replacement Pin
Code-o-mat29-Jan-10 10:18
Code-o-mat29-Jan-10 10:18 
GeneralRe: Windows Shell Replacement Pin
Richard MacCutchan29-Jan-10 22:08
mveRichard MacCutchan29-Jan-10 22:08 
GeneralRe: Windows Shell Replacement Pin
Code-o-mat30-Jan-10 6:18
Code-o-mat30-Jan-10 6:18 

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.