Process terminated with status -1073741819

This is a discussion on Process terminated with status -1073741819 within the C Programming forums, part of the General Programming Boards category; Hi, I use Code::Blocks and I'm writing a program that is supposed to count the number of possible variations between ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    10

    Process terminated with status -1073741819

    Hi, I use Code::Blocks and I'm writing a program that is supposed to count the number of possible variations between 10 letters of the alphabet. The program compiles, but once I run it, it crashes and gives me this error:

    Process terminated with status -1073741819
    And I have no clue why is that happening. Here is the code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void move(char *one, char *two);
    
    main()
    {
        char alf[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
        int count, index, max = 0;
    
        for (index = 9; strcmp(alf[9], 'a') != 0; count++) {
           if (index == 0) {
              index = 9;
              continue;
           }
           move(&alf[index], &alf[index - 1]);
           max++;
        }
    
        printf("%d", max);
    
        return 0;
    }
    
    void move(char *one, char *two)
    {
        int aux;
    
        aux = *two;
        *two = *one;
        *one = aux;
    }
    Any help will be welcome.
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    74
    you aren't changing the variable index, so your loop is stuck.

    count is doing nothing as well.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2,919
    What is the following line doing?

    Code:
     for (index = 9; strcmp(alf[9], 'a') != 0; count++) {
    You might take a look at this tutorial.

    for loop tutorial.

    Jim

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    strcmp compares character arrays not characters.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Also, you don't need to count them. The number of permutations will always be n! (n-factorial) where n is the size of your array( in your case 10).

    So the answer is 10! which is a pretty large number.

    If by variations you mean permutations that may include repetitions, then there is a formula for that too.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > Process terminated with status -1073741819
    Convert it to hex, and you get 0xC0000005

    Searching for this gets you knowledge that such an error is an access violation (the windows equivalent of segmentation fault).

    Reduced, your program tried to access out of bound memory.

    Did you get these warnings when you compiled?
    Code:
    foo.c: In function ‘main’:
    foo.c:12: warning: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast
    /usr/include/string.h:142: note: expected ‘const char *’ but argument is of type ‘char’
    foo.c:12: warning: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast
    /usr/include/string.h:142: note: expected ‘const char *’ but argument is of type ‘int’
    DO NOT IGNORE warnings, especially warnings which mention the word "pointer".
    You're almost certainly screwing up badly enough to get a run time fault.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why isn't the execlp() function doing anything?
    By jsrig88 in forum C Programming
    Replies: 5
    Last Post: 10-12-2009, 11:09 AM
  2. sequenceing or queueing multiple process
    By sv_joshi_pune in forum Windows Programming
    Replies: 1
    Last Post: 08-14-2009, 10:43 AM
  3. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 02:43 AM
  4. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 08:53 AM
  5. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 06:31 AM

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