Thread: String disection

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    99

    String disection

    This program will take in an input of "Name:Information." The program will then search through the string until the colon is met and replace the colon with a '\0'. I am only up to this point and wanted to test it to see if I got any problems in which it compiles fine but it falls out when it gets to the line assigning the '\0' character.
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    	char str[50];
    	char *p;
    	printf("string in the format \"Name:Information\": ");
    	fgets( str, sizeof(str), stdin);
    	
       p = strchr(str, ':');
       if ( p ) *p='\0';
       getch();
       return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    Yea actually I had tried that as more of an error catcher and it did the same thing. It does look to me like is should run but it doesn't, got me kinda stumped.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    Windows 98, DevC++ 4.9.7.0

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>but it falls out when it gets to the line assigning the '\0' character
    What exactly does that mean? Can you explain the symptoms a bit more please.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    When I run the program, after entering the input needed I get a message box that say "Program has performed an illegal operation, contact vendor blah blah"

    Details Portion:
    STRING3 caused an invalid page fault in
    module MSVCRT.DLL at 0187:780243c2.
    Registers:
    EAX=0000004e CS=0187 EIP=780243c2 EFLGS=00010213
    EBX=00000000 SS=018f ESP=0073fd94 EBP=0073fdc8
    ECX=7803bb90 DS=018f ESI=7803bb90 FS=3ea7
    EDX=00000101 ES=018f EDI=00000000 GS=0000
    Bytes at CS:EIP:
    88 07 47 89 7d e0 3c 0a 75 bd 80 27 00 eb da 8b
    Stack dump:
    00000000 817cd9b0 00530000 00000000 0000004e 00000029 7803bb90 0073fdd8 0073fbc4 0073ff68 7800f56a 780353f0 00000000 0073fdf8 0040129d 00000000

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What, the code as shown in your first post gives you an illegal op? (just clarifying)
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    Yes it does. That is the dump and error message that it gives me when I run the program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM