Thread: reading a string!!!

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Post reading a string!!!

    i have a polynomial function p(x)=3x^2+2x-2
    how can i get the constant values and exponents for instance
    (3,2),(2,0),(-2,0) in a linkes list?
    i think i have to get this polynomial function as a string isthis a good way??
    Last edited by condorx; 12-07-2002 at 11:01 AM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Do you want to extract numbers from a string?

    Kuphryn

  3. #3
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    Easy.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct list{int constant, exponent; struct list *next;}LIST;
    
    main(){
        int c, e;
        LIST *head = malloc(sizeof(LIST)), *walk = head;
    
        while (scanf("(%d,%d),", &c, &e) == 2){
            walk->next = malloc(sizeof(LIST));
            walk = walk->next;
            walk->constant = c;
            walk->exponent = e;
            walk->next = 0;
        }
    
        for (walk = head->next; walk; walk = walk->next)
            printf("(%d,%d)\n", walk->constant, walk->exponent );
    }
    Input:
    (3,2),(2,0),(-2,0)

    Output:
    (3,2)
    (2,0)
    (-2,0)

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    80
    simply i want to take the constant values and exponent of x to another integer matrix[5][2]
    for instance
    p(x)=3x^2+2x

    array take all the the integers array[1][0]=3 array[1][1]=2 and so on..

  5. #5
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    First you want a linked list now you want an array? I think you should make up your mind about how to do it before you start doing it.

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    80
    no i used array to illustrate what i want?i thought it is easier

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. IRC, reading the stream
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 08-03-2006, 05:34 PM
  4. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  5. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 05:13 PM