Thread: How to run C code under VC environment?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    11

    Question How to run C code under VC environment?

    I always get error report running C program in VC. It seems that some symbol interpretation not installed? How to deal with it?



    Thanks
    robin

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    You have two choices:
    1) Post your errors so that we can help you.
    2) Google your errors.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    When I step into code:
    have such error for any fuction:

    Unhandled exception in ...exe. :0xC0000005:access violation

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    I guess I should install some "patch" for VC6.0 that make it can run any ansi C code.
    I tried my VC6.0 and in common lab. Both can not run c code.
    anybody give an solution?

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Fix the bug(s) in your code?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Post your code. Even though VC6 isn't great in terms of ANSI compatibility, it's not too bad.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Your "access violation" most likely has nothing to do with the compiler, and more to do with buggy code you've written.

    I suggest posting your code here.

  8. #8
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    sorry.

    How to post code? Format?

  9. #9

  10. #10
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    The main function is like following
    =================================
    Code:
    # include <stdio.h>
    # include <string.h>
    # include <stdlib.h>
    # include <conio.h>
    # define TRUE 1
    # define FALSE 0
    # define SIZE 101
    
    long int record_arr();
    void insertion_sort();
    void merge_sort(long m,long n);
    void merge(long m,long k,long n);
    void quick_sort(long m,long n);
    long int partition(long m,long n);
    
    long int array[SIZE];
    long int c[SIZE];
    long i,j,m,n;
    long val,max;
    long k;
    char str[3]={'i','m','q'};
    
     FILE *in,*out;
    
    main()
    { 
      char test='i';
      if((in=fopen("in.txt","rt"))==NULL)
        {printf("cannot open input file\n");
         exit(0);
        }
      if((out=fopen("out.txt","wt"))==NULL)
        {printf("cannot open output file\n");
         exit(0);
        }
      if(strcmp(test,str[0])==0)
      {   max=record_arr();
    	  insertion_sort();
    	  for(i=0;i<max;i++)
    		  fprintf(out,"%d \n",array[i]);
      }
      else if(strcmp(test,str[1])==0)
      { m=0;
        n=record_arr();
    	 merge_sort(m,n-1);
    	  for(i=0;i<n;i++)
    		  fprintf(out,"%d \n",array[i]);
      }
    	 
      else if(strcmp(test,str[2])==0)
      { m=0;
        n=record_arr();		
    	quick_sort(m,n-1);
    	 for(i=0;i<n;i++)
    		fprintf(out,"%d \n",array[i]);
      }
      else
      {
    	printf("Sorting type parameter error!, try to use i/m/q for type of sorting \n");
    	exit(0);
      }
      printf("program finished now!");
     fclose(in);
     fclose(out);
    // getch();
    }

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Both arguments to strcpy are supposed to be strings -- test, str[0], str[1], and str[2] are single characters (not strings). If you just want to do a single-character compare, do this:
    Code:
    if(test == str[0])
    Last edited by Dave_Sinkula; 04-05-2005 at 04:35 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Registered User
    Join Date
    Mar 2005
    Posts
    11
    Thanks
    Dave_Sinkula

    I think that's the problem.


    But why it is valid in turbo c?

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > But why it is valid in turbo c?
    It isn't.
    The compiler is probably too dumb to generate an error message.
    DOS has NO memory protection at all, so you're free to overwrite anything you like. Of course, later on, random other things go wrong and your program then dies.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why my code works only in debug mode?
    By pingpangpang in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2007, 12:39 PM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Determining required flops to run C code
    By mollyann in forum C Programming
    Replies: 5
    Last Post: 03-30-2005, 01:28 PM
  4. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM