CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008
    Posts
    1

    Split input from a read buffer into strings

    this is is the input file :

    Option = NoPathCompression
    S = {a, b, c, d, e, f, g}
    MakeUnionFind(S)
    Union(a,d), Union(b,e), Union(c,f)
    Union(c,g), Union(e,a)
    Union(b,g)

    and the output should be :

    a, b, c, d, e, f, g
    da, eb, fc, g
    daeb, fcg
    daefbcg

    I am trying to implement MakeUnionFind(S)
    S = {a, b, c, d, e, f, g}

    this is one of the line that I am reading from a file. I have to create pointers for each of the member of S with the name of the member that points to itself in a function MakeUnionFind(S). The set s can contains numbers as well as strings. What I am trying to do here is to read the line in a buffer then trying to create an array from it and then planning to use that array to create pointers for each member of the set but I am not sure if my approach is right. Please help me, how can accomplish this task.
    string line;
    ifstream readfile ("C:\\test.txt");
    getline (readfile,line);

    Now I have to do split this input which is in buffer 'line' into array of strings where ',' is the delimeter. This is the part I am not able to do and I have to send these strings to the function one by one MakeUnionFind(S). In MakeUnionFind(S), we initialize a record for each element that belongs to S with a pointer than points to itself (or is defined as a NULL pointer) to indicate that v is in its own set.

    Please let me know how can I accomplish this. Thanks for all your help in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    111

    Re: Split input from a read buffer into strings

    Regarding your query related to splitting you can try using strtok() function with ',' as the seperator, but first you will have to use strchr() to find the location for '{' in your input string.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured