Thread: Problems using CYGWIN

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    18

    Question Problems using CYGWIN

    I compile my program, which seems to work fine using "gcc RadixSort.c -o RadixSort" and then my .exe is created. Then I use the following command "./RadixSort" to try and run it, but it does nothing, it seems to be doing something for a second and then it goes right back to the command prompt.... It's acting really weird. Any Ideas?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Without seeing your source code, who knows.

    Was it expecting some command line parameters perhaps?
    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.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    18

    Post

    I printed test outputs to make sure it was going into the program

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    RadixSort(int aList[]){
    
    	// int temp[16];
    	int temp[5];
    	int i,j;
    	int index=0;
    
    	printf("Test1\n");
    	
    	for(i=0;i<=5;i++){
    		for(j=0;j<=9;j++){
    			if((aList[i]%10) == j){
    				temp[index] = aList[i];
    				index++;
    			}
    		}
    	}
    	PrintArray(temp);
    }
    
    PrintArray(int temp[]){
    
    	int i;
    
    	for(i=0;i<=5;i++)
    		printf("%d\n",temp[i]);
    }
    
    int main(){
    
    	//int aList[16] = {265,69,89,132,240,77,2,189,232,420,777,823,927,352,845,201};
    	printf("Test0\n");
    	int aList[5] = {777, 420, 281, 123, 999};
    	RadixSort(aList);
    
    return 0;}
    Here is my output:

    MyKoL@MyKoL-PC ~
    $ gcc RadixSort.c -o RadixSort

    MyKoL@MyKoL-PC ~
    $ ./RadixSort

    MyKoL@MyKoL-PC ~
    $

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Your bizarre behavior was probably a result of my third point, array bounds violations, but it's hard to say, since I couldn't really reproduce that error (I did get a seg fault once, but that was once and I couldn't repeat it, so who knows). I have a few suggestions though:

    First, if you don't specify a return type for a function, C assumes it's an int, not void. Then it complains about you not returning a value when it's expecting you to return int. Explicitly declare RadixSort and PrintArray to "return" void.

    Second, put a prototype for PrintArray at the top of the file, or move it above RadixSort to get rid of the implicit declaration warning. You should be getting this warning, because you should be compiling with all errors and warnings on (-Wall flag for gcc).

    Third, declaring an array of length 5 means you can use indexes 0..4. Your for loops should thus be written
    Code:
    for (i = 0; for i < 5; i++)
    You were useing i <= 5 which accesses a garbage 6th element.

    Fourth, you have your loops reversed in RadixSort. What you were doing was taking each element of a, and checking it's last digit. If it's last digit was something in the range of 0-9 (of course it was!), you were putting it in temp. That meant that temp contained a copy of the original array and never sorted it.

    Lastly, you need to repeat the logic in RadixSort for the 10's, 100's, 1000's columns, etc for each of your array elements.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    Ok, so is it bad programming to neglect to declare the function type I suppose, but I saw that used at StackOverflow.com and assumed that was correct, along the array size. I though it looked funny too, but I assumed it was right because I'm new to C, I've used C++ and PERL before. So not sure about the particulars in this language.

    I decided to uninstall CYGWIN and reinstall it too, so once that is done I'll correct my errors and hopefully that will work.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I highly doubt a bad install of Cygwin was the culprit, but since you've already started, I guess there isn't much we can do. If you do continue to have trouble however, and are sure it's Cygwin's fault, you could try installing VMWare Player (or some other free virtualization program) and a regular Linux distro, like Fedora or Ubuntu.

    I strongly suggest you become comfortable with gdb and learn to use a debugger, as it is indispensable for tracking down bizarre errors like you encountered. Since that takes time to master, you can keep using your printf debug output, but you should use fprintf with stderr instead. stdout is buffered, and doesn't print anything on the screen until it gets a newline, so it's very possible (maybe not in this case, but in general) that your program has "printed" some debug output, but catches a seg fault before that shows up on the screen, and you think your program is crashing in a totally different place than it actually is. stderr on the other hand is unbuffered, and output shows up immediately. This is also nice, since you can redirect stdout (real program output) and stderr (debug output) to different files for later analysis. As an example,
    Code:
     server$ ./RadixSort 1>programoutput.txt 2>debugoutput.txt
    In the future, if you're using printf statements for debug output

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    Only the debugoutput.txt had anything, this is what I found:

    bash: /.RadixSort: No such file or directory
    I reinstalled, still having the same occurring issues. I even commented out almost the whole program and still am unable to get any results from my code. not sure what has happened.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > bash: /.RadixSort: No such file or directory
    That was just your finger trouble on that test, typing 'slash-dot' instead of 'dot-slash'
    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.

  9. #9
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    Quote Originally Posted by Salem View Post
    > bash: /.RadixSort: No such file or directory
    That was just your finger trouble on that test, typing 'slash-dot' instead of 'dot-slash'

    That was the output I got to the txt file that the prior person suggested for debugging.

    I did type in
    Code:
    ./RadixSort
    to run my code, have any other ideas as to what the issue might be?

  10. #10
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    So I'm pretty sure that bash didn't modify what you typed, and that you actually did have a typo (unless your program prints that message to stderr). Just to be sure though, feel free to paste some of your terminal output from an instance of you running the program here, without the 1>... and 2>... that I suggested. Also, if you've made any significant changes to the code, post your new version so we can test that and check it for errors.

  11. #11
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    I honestly think its a cygwin error, not sure what is happening and why nothing is displayed.

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    void RadixSort(int aList[]){
    	int temp[5];
    	int i, j;
    	int index=0;
    
    	printf("Test\n");
    	for(j=0; j<=9; j++){
    		for(i=0;i<5;i++){
    			if((aList[i]%10) == j){
    				temp[index] = aList[i];
    				index++;
    			}
    		}
    	}
    }
    
    void PrintArray(int temp[]){
    	int i;
    
    	for(i=0; i<5; i++){
    		printf("%d\n",temp[i]);
    	}
    }
    
    int main(){
    	printf("Test0\n");
    	int aList[5] = {777,420,281,123,999};
    	RadixSort(aList);
    return 0;}
    MyKoL@MyKoL-PC ~
    $ gcc -g RadixSort.c -o RadixSort

    MyKoL@MyKoL-PC ~
    $ ./RadixSort

    MyKoL@MyKoL-PC ~
    $

  12. #12
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Very interesting indeed. I don't have any problems. I got the "Test0" and "Test" outputs, then I added my own debug output to print different stages of the sorting as well as the final aList and temp arrays at the end of the RadixSort routine. You are now correctly sorting on the 1's column, but still need to modify your sort routine to cover all possible number sizes. You're on the right track though. Maybe it's just time to ditch Cygwin and install a Linux VM or something.

  13. #13
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    Lo and behold, F#$%(@! Windows 7, I ran cygwin as an admin and the output showed up! but then I had to system restore because my net suddenly quit working and my skype would works. Something went crazy and now I'm fixing it. If I have any other issues I'll be sure to ask. THANKS!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ 2010 express problems
    By dnj23 in forum Windows Programming
    Replies: 6
    Last Post: 08-10-2010, 06:16 AM
  2. Most Common problems in C
    By Bayint Naung in forum C Programming
    Replies: 18
    Last Post: 06-02-2010, 08:20 PM
  3. Cygwin and coLinux
    By Mario F. in forum Tech Board
    Replies: 8
    Last Post: 07-03-2006, 02:00 PM
  4. cygwin vs win32 help
    By dynomyte in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2006, 01:02 AM
  5. Cygwin Server
    By osal in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-07-2005, 12:58 PM