pattern checking in a string question..

This is a discussion on pattern checking in a string question.. within the C Programming forums, part of the General Programming Boards category; in my previous problem i did exactly the same thing for inputting numbers into a 2d array . why its ...

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    in my previous problem i did exactly the same thing for inputting numbers into a 2d array .
    why its not letting me input chars in a row?
    Code:
    int main() {
        int index;
        int str[40];
        int i;
        int length;
    
     printf("enter length\n");
     scanf("%d",&length);
     printf("enter string\n");
     for(index;index<length;index++){
       scanf("%c",&str[index]); 
     }
     i=getchar();

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Quote Originally Posted by transgalactic2
    in my previous problem i did exactly the same thing for inputting numbers into a 2d array .
    why its not letting me input chars in a row?
    Note that your array is an array of ints, not chars. If you really want to read char by char in a loop, then it probably makes more sense to just call getchar() instead of using scanf().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i want to enter my string
    from a row of chars which i enter myself

    in every way possible

    i tried
    Code:
    int main() {
        int index;
        int str[40];
        int i;
        int length;
    
     printf("enter length\n");
     scanf("%d",&length);
     printf("enter string\n");
    
       scanf("%c",&str); //13
    
    
    
     printf("%d",checkPoly(str,length));
     return 0;
    }

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    For starters, change this:
    Code:
    int str[40];
    to:
    Code:
    char str[40];
    After that your earlier code would probably work, just that it is a little weird to use scanf() in a loop to read character by character.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i did that.
    it doesnt let me enter the string in a row
    it doesnt even let me type anthing
    i dont mind changing the method

    i want it to let me enter the string by a row
    Code:
    #include <stdio.h>
    int checkPoly(char str[], int length);
    
    int main() {
        int index;
        char str[40];
        int i;
        int length;
    
     printf("enter length\n");
     scanf("%d",&length);
     printf("enter string\n");
     for(index;index<length;index++){
       scanf("%c",&str[index]); 
     }
     i=getchar();

  6. #21
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    You never initialise 'index' to any value before you actually use it.

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    There is another potential problem in that the user would have to input enough characters to fill the entire string, and you do not account for the null terminator.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    ok i looked up in the javadoc of the file and it should
    recognize "(1.0+1.0i)x^1 +(1.0+1.0i)x^0"

    but i cant see that in the code
    there is no mention for "i' char in the code

    ??
    Last edited by transgalactic2; 12-26-2008 at 02:49 PM.

  9. #24
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    and it doesnt work it doesnt say 1 on that example

    i cant understand how its being built.

    what each part is suppossed to do in order to check for a pattern

  10. #25
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    this program is an example to a pattern checking program

    i want to check other patterns in the string

    how to pattern checking proccess works?

  11. #26
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Quote Originally Posted by transgalactic2
    and it doesnt work it doesnt say 1 on that example
    Cross reference with the Java version: does the Java program return the correct answer? If it does, then perhaps you converted the program wrongly. If not, then clearly there is a bug in the program (or maybe the documentation, or both).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #27
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    in general is this the way
    i need to do pattern checking?

    or there is an easier way

  13. #28
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Quote Originally Posted by transgalactic2
    in general is this the way
    i need to do pattern checking?
    That depends on what you mean by "the way". Certainly checking if input follows some format means parsing the input.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #29
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    the way i meant "complex loop" system

  15. #30
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Quote Originally Posted by transgalactic2
    the way i meant "complex loop" system
    Yes, though there would be the use of functions to hide the complexity, and with say, a recursive descent parser you would likely use recursion instead of iteration.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 07:52 PM
  5. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21