#Help with buffers
163 messages · Page 1 of 1 (latest)
is there anyway i can copy from vim
what computer are you on
mac
open <filename> -a textedit
then just copy the relevant parts
or just the entire thing and put it in a pastebin and i'll take a looksee
erm, it might be -a TextEdit, i cant remember if it's case sensitive
(alternatively, you can cat <filename> | pbcopy. fun fact, on mac, pbcopy is a command where it'll copy its stdin to your clipboard. pbpaste will write your entire clipboard to stdout)
theres the paste bin
got example input?
included in the image but i can get that too
do u need that too
gimmie a sec to read stuff
okay thank you
and which part specifically is the weird part
so in this example
oh ok cours ebefore
that means you havent reset a variable to 0
first off, have you tried breaking this out into separate functions?
no i haven't
it'll make it significantly easier and will probably solve the bug
erm, can you show me the definition of enum course_type_t
enum course_type_t {
LECTURE,
PSO,
LABORATORY,
RECITATION,
INDEPENDENT,
};
?? lol
int lecture = (int) LECTURE;
int pso = (int) PSO;
int lab = (int) LABORATORY;
int rec = (int) RECITATION;
int ind = (int) INDEPENDENT;
ah i see
well, so here's a fun fact abotu C for you
seems to be 0 1 2 3 4
so when you say ```c
enum foo {
THING1,
THING2,
...
};
it'll essentially define a global constant called THING1, whose type is an enum foo (which is 100% interchangeable with int)
so all those int lecture = ... declarations are irrelevant
in fact, this entire block ```c
if(reader == 2) {
if(enum_int == lecture) {
type = LECTURE;
}
else if(enum_int == pso) {
type = PSO;
}
else if(enum_int == lab){
type = LABORATORY;
}
else if(enum_int == rec) {
type = RECITATION;
}
else if(enum_int == ind) {
type = INDEPENDENT;
}
}
just do ```c
reader = fscanf(fp, "|%d|%d\n", &type, &credit_hours);
printf("int %d, hours %d\n", type, credit_hours);
so i could just see if the num is just equal to the type itesself
yeah, so enums start at 0, and count up from there
so generally peopel do this
enum whatever {
VARIANT1,
VARIANT2,
...,
VARIANTWHATEVER,
PRIVATE_LAST_VARIANT
};
and then they just check to see if their enum whatever they just read is < PRIVATE_LAST_VARIANT
a-la
ahhhhhhh
reader = fscanf(fp, "|%d|%d\n", &enum_int, &credit_hours);
printf("int %d, hours %d\n", enum_int, credit_hours);
if (reader == 2 && enum_int >= PRIVATE_LAST_VARIANT)
error_out_with_messagE("bad enum variant: %d", enum_int);
anyways, so my first recommendation is to break this apart into functions
your entire do ... while loop should be a function (maybe call it "get courses" ?)
whenever a chunk of code is longer than 5 or so lines, generally breaking it out into a function is the right idea
my do while is essentially the whole entire function
yeah
well, ok, step back
i'm giving you the stackoverflow "do it this way not that way" answer lol
would you rather i just help you find the bug or to clean it up too
fix the bug, im kind of in a time crunch to submit this
sounds good
how much of a time crunch? out of curiosity
like, hours? or a day or so
got until noon tomorrow but i wanna sleep
mk
can you zip up everythign you have and send it to me
and stay tuned i'll have questions
im on a linux shell from my university so i cant really zip any files
i could pastebin some test cases i do have though
it's useless without the hw6.h header
oo wait
ok hold on
printf("---------------------------------------------\n");
printf("g num course: %d\n", g_course_count);
printf("course name: %s\n", course.course_name);
printf("pre reqs: ");
for(int i = 0; i < MAX_PREREQ; i++) {
printf("%s ", course.prerequisites[i]);
}
printf("\n");
printf("enum #: %d\n", (int) course.course_type);
printf("hours: %d\n", course.credit_hours);
printf("---------------------------------------------\n");
is hte issue the course.prerequesites being printed incorrectly?
OH
i see your issue
for(int i = 0; i < MAX_PREREQ; i++) {
for(int i = 0; i < num_prereq; i++) {
try that lol
i cant believe i didnt catch that at the start
that's still an issue though
or in the struct rather
also, your indentation is all over the place lol
what's this reader variable
also, can you rerun it with more clearly defined error cases
or, rather
which thing in your example input is incorrect
which i also fail
how about this
do course1, course2, etc. and then for prereqs to course1-prereq1, course1-prereq2,e tc
then show me the output of that
so if the name or any prereqs are over 200 chars, its a buffer error, if its less but over the max len of 80 you truncate it to fit into the course name
thats the buffer error
which i also dont know how im not dealing with
oh so youre sure it's a buffer error
almost positive
ok
i'll take a closer look at that, i was looking at the variables
can i see the declaration of course_t
is it how i read the prerequisites in? because some classes do not have pre requisites and you also do not know how many pre reqs they have
it's very very weird that it doesnt have the count of prereqs in it
and each pre req must have ? before it
i presume you didnt make that type
nope it was provided
that's fuckign weird
yea
what's MAX_PREREQ, and MAX_NAME_LEN
max pre req is 3 and name len is 80
okay
pol 348 should not have KOR
i mightve found something
gimme a sec
so when you told me to change the for loop printing to num_prereq instead of MAX_PREREQ it printed the correct values
which means its still storing it even though im restricting it
oo
and index 2 was empty
but its weird cause i reset num_prereq at the end of the do while
yeah
@vernal badger Has your question been resolved? If so, run !solved :)
rippp
got it
lets go
im such an idiot
i should've initialized the course at the beginning of the do while
oh nice
im falling asleep now im glad you figured it out lol
mark the thread as done
!solved
Thank you and let us know if you have any more questions!
@vernal badger
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
👍