User Profile

Collapse

Profile Sidebar

Collapse
cting76
cting76
Last Activity: Apr 5 '07, 05:44 PM
Joined: Mar 11 '07
Location: Lubbock, TX
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • cting76
    replied to strtok question
    in C
    Alright I have modified my code into this:

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    #define index 5
    
    struct am{
    	string rule;
    	int priority;
    }set[index];
    
    void printset(am amg)
    {
    	cout<<amg.rule<<endl;
    	cout<<amg.priority<<endl;
    }
    ...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to strtok question
    in C
    Shouldn't num=strtok(NULL ,"(")) return NULL if there's no more element after the last ")"?...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to strtok question
    in C
    Thank you! I wasn't aware of the difference between c[i]=infile.get() and infile.get(c,25 6). Now the program can read the line just fine. However, it hangs again if the input is like this:

    (arule, 10), (brule,20)(crul e, 30)(drule, 40), (erule, 50)(frule, 60)

    I use Visual Studio and it simply says the program (the one I wrote) has stopped working. The output would look like this:

    arule
    10
    ...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to strtok question
    in C
    Will someone be so kind to point out why my program hangs? It doesn't give out any error message other than "<program_n ame has stopped working>".

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    void main()
    {
    	ifstream infile;
    	char c[256],str[64];
    	char *rules[50];
    	int priority[50];
    	int i=0;
    	char *num;
    ...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to strtok question
    in C
    Thank you. That fixes the problem.

    I then modified the input into:

    Code:
    char line[100]="(arule, 12), (brule, 21), (zrule, 70), (drule, 25), (erule, 10)(frule, 3)(grule, 20), (srule, 100)";
    Notice that there's no "," between "(erule, 10)", "(frule, 3)", and "(grule, 20)". What I want to do is, let the program read from "(arule, 12)" until "(erule,10) ",...
    See more | Go to post

    Leave a comment:


  • cting76
    started a topic strtok question
    in C

    strtok question

    If I understand it correctly, strtok scans from the first character after the separator. The code below:
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    void main()
    {
    	char *rules[50];
    	int priority[50];
    	int i=0;
    	char line[100]=" (arule, 12), (brule, 21), (zrule, 70), (drule, 25), (erule, 10)(frule, 3)(grule, 20), (srule, 100)";
    ...
    See more | Go to post

  • cting76
    replied to fstream to array
    in C
    I kept getting this error when running the program under Visual C++:

    Debug Assertion Failed!
    Program: ...
    File: strtol.c
    Line: 94

    Expression: nptr != NULL

    What did I do wrong? :(

    The code:

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    void main()
    {
    
    	ifstream infile;
    	char
    ...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to fstream to array
    in C
    ok... I understand the concept. Basically I have to write code that would treat everything after '(' and before ',' as string, and everything after ',' and before ')' as int, and if there's a ',' after ')', repeat until there's no ',' after ')'. My question is, what fuction should I use? I mean, how do you tell the program to "read" each character and determine if it's a '(', ',', ')', a letter or a number?

    Thanks!...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to fstream to array
    in C
    Maybe my flow of thought isn't correct. What I'm trying to do is to write codes that would read lines of data from a txt file, then run a heapsort on them. For example, given the following data:

    (arule, 12), (brule, 21), (zrule, 70), (drule, 25), (erule, 10)
    (frule, 3)
    (grule, 20), (srule, 100)

    The program should read and sort the first line of data in an array, then insert the 2nd line, sort the whole...
    See more | Go to post

    Leave a comment:


  • cting76
    replied to fstream to array
    in C
    What about reading a line like below from a file, say, "input.txt" :

    (arule, 12), (brule, 21), (zrule, 70), (drule, 25), (erule, 10)

    I am trying to put the first parameters, i.e. arule,brule,etc into an array, say, [I]rules, and the numbers into another array, say numbers[j].

    I assume the first array would have to be string type. When I use strtok it tells me it cannot convert string to char....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...