Thread: String error

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    147

    String error

    I have a striing which is like :

    "#$Francis"

    so,

    char *u;
    char str[25]="#$Francis";
    u = strstr(str, "#$");
    u++;u++;

    so the u pointer now points to 'F'.

    when i run a loop to print out character by character from F to s in Francis, it somehow keeps stopping at 'n', it does not proceed to print out c, i or s, but instead prints out many many weird characters...

    any idea wat's wrong ehre?
    Only by the cross are you saved...

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    60

    RE: string problem

    It looks fine to me. Maybe try writing a function that ignores # and $ or whatever and prints everything else. Whenever there seems to be no possible answer to a bug, it is best to cross reference and appoach it from different angles.

    Code:
    int a = 0;
    
    while (theString[a++])
    {
       if(theString[a] == EOF);
          return 0;
       if(theString[a] == '#' || theString[a] == '$')
          continue;
       else if(theString[a] == '\n')
          putchar('\n');   
       putc(theString[a]);
    }
    Hope that helps a little.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    okok, thanx, it worked!

    do u know if there is a function in C whereby i can convert a string to upper case or vice versa?
    Only by the cross are you saved...

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    toupper() tolower(). Loop through your string using these functions on the individual characters.

    With your original problem, show the loop you are using to print out Francis.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    isn't this onli for single characters?

    i tried it on my string, and i got so many warning messages...

    how do i do it for a strinG?
    Only by the cross are you saved...

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> Loop through your string using these functions on the individual characters.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    okay, done that

    another thing is, er.........i have a password field where users enter their password...
    is there any function in C which masks the characters for u? or must we do this ourselves?
    Only by the cross are you saved...

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    I can't think of a function in C, C++ yes and with operating system API functions, yes, I think you may just as well do it yourself.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    is there any function in C which masks the characters for u? or must we do this ourselves?
    Common question use puts to put a * on screen after reading in one character thus replacing the character with the *.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM