Printing a string is crashing Windows

This is a discussion on Printing a string is crashing Windows within the C Programming forums, part of the General Programming Boards category; I am trying to create a C program on Windows Vista, and there is one line of code that consistently ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    5

    Printing a string is crashing Windows

    I am trying to create a C program on Windows Vista, and there is one line of code that consistently crashes a.exe during run time.

    printf("%s", *pointer);

    (*pointer is pointing to a string of characters)


    When I remove this line, there is no problem. When I change %s to %c, there is no problem and it simply prints the first char of the string. I have included a video of this happening.

    I am using GCC on MinGW (a compiler for Windows)

    http://www.danedesigns.com/problem.avi

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Unless "pointer" is a pointer to a character pointer, you're doing it wrong. Remove the: *


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    5
    Here is more of the code:

    char arr[50][100];
    char *pointer;

    arr[0][0] = "string";

    *pointer = arr[0][0];

    printf("%s", *pointer);




    Shouldn't that print out "string"?
    Last edited by tox0tes; 05-21-2009 at 09:28 PM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Unless "pointer" is a pointer to a character pointer, you're doing it wrong. Remove the: *

    I could have sworn I just typed that up there a bit...


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    5
    after removing the star, instead of getting "string" as an output, I get "s '"

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That's because you're still using %c. Either that or because your assignment of the string as you've attempted, is horribly wrong.
    Code:
    #include<stdio.h>
    int main( void )
    {
        char array[] = "string";
        char *ptr = array;
    
        printf("%s\n", ptr );
    
        return 0;
    }

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    5
    thanks for your help, i have figured out my problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program printing ".N=?" at beginning of string
    By bertazoid in forum C Programming
    Replies: 22
    Last Post: 02-10-2009, 12:14 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Replies: 8
    Last Post: 03-31-2006, 08:15 AM
  5. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 03:58 AM

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