Jump to content

Help with C class please

joemomma22

-snip-

indexOfLargest should return indLarge, not curr

curr will always return "numElements", which may make you access unallocated memory, which would cause crashes (and wrong random results)

Link to comment
Share on other sites

Link to post
Share on other sites

typing the previous post was the ultimate typo/error galore

i even ended up doubleposting

please someone delete this post

Link to comment
Share on other sites

Link to post
Share on other sites

indexOfLargest should return indLarge, not curr

curr will always return "numElements", which may make you access unallocated memory, which would cause crashes (and wrong random results)

 

 

typing the previous post was the ultimate typo/error galore

i even ended up doubleposting

please someone delete this post

haha too late now.  xP and yeah changing curr to indlarge was kinda a duh moment. but its still crashing

Link to comment
Share on other sites

Link to post
Share on other sites

haha too late now.  xP and yeah changing curr to indlarge was kinda a duh moment. but its still crashing

it works for me

does Strings.dat exist?

 

debug it a bit, try removing function calls from the main until it stops crashing

and check what is returned by fopen: if it's NULL, then shit happened with your file

Link to comment
Share on other sites

Link to post
Share on other sites

If you are running it from within Code::Blocks, since you have a relative (working dir) path you need to set your project's working dir

 

Project -> Properties -> Build Targets tab

 

2Rh3QcR.png

 

Set that to where ever your Strings.dat file is

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

it works for me

does Strings.dat exist?

 

debug it a bit, try removing function calls from the main until it stops crashing

and check what is returned by fopen: if it's NULL, then shit happened with your file

 

 

If you are running it from within Code::Blocks, since you have a relative (working dir) path you need to set your project's working dir

 

Project -> Properties -> Build Targets tab

 

2Rh3QcR.png

 

Set that to where ever your Strings.dat file is

if i comment out the swap call in selSort it runs printing out the array file twice (obviously unsorted)

Link to comment
Share on other sites

Link to post
Share on other sites

if i comment out the swap call in selSort it runs printing out the array file twice (obviously unsorted)

are you sure you corrected the indexOfLargest thing? and recompiled?
Link to comment
Share on other sites

Link to post
Share on other sites

I think it might be an out of bounds error.

 

Consider the first swap

void selSort(char strings[][31], int count){    int loc;    int last = count;    for (last; last >= 1; --last)    {        loc = indexOfLargest(strings, last + 1);        swap(strings, loc, last); //So you are passing in the strings, location and for the first time last will = count    }}void swap(char strings[][31], int loc, int last){    char temp[31];    strcpy(temp, strings[loc]);    strcpy(strings[loc], strings[last]); //You are using last, but if last = count you are actually accessing the string one past the end of your array    strcpy(strings[last], temp); //So you need to correct for that, remember your index is from 0 to count-1}

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

I thank everyone again for all the help. I turned my lab in incomplete. I ended up with an a- in the class this is what brought it down from an a+ but that's okay

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×