This post is far too long. No one's gonna read it and I know it!A-mazing. Just look at the beauty of it. It's as if Picasso graced his paintbrush on this magnificent program! -Oh wait, it doesn't work? Shucks!
Finally I've been able to completely pass all the tests for Assignment 1 on Visual Studio. Just now I compiled on Linux or Matrix as well. Works fine. I had to make some dirty fixes here and there, but I'll try and clean it up tomorrow - Oh wait, it IS tomorrow...
I've been worrying incessantly about Co-op placements, my resume/cover letter, and interviews (the one I was most excited about was the one with
RIM...), it's been feeling a bit cramped. Since I haven't really been active in posting on my blog (I'm still not used to it, but I should think of it like writing a much more detailed log sheet), I'm gonna run through a bunch of things I ran into since I started this assignment.
The code below is something I started off with in the io_edit function. It was being used to do editing when hitting characters, with insert mode on. Picture the text editor that you use or the email application you use to send out an email. By default on a Windows machine, typing would actually insert letters. To me this is natural, but it's something you have to think about when you're making a text editor from scratch like this.
Here's an example:
ABCD| EFGH.
If you hit a couple letters when your cursor(|) is after the D, you'd get:
ABCDKJL| EFGH.
To do that in a program, you'd have to break it down. The line you have with the text is stored in a string. If you tried to just insert something into a string, it wouldn't work. Later on we'd probably use a stack or queue structure but it's not available to us at this point. My first thought was to make a for loop that stored each element of the string into a backup string called "stored" (clever hunh?). Then later on I'd put it all back with another for loop, after inserting the character needed. Like so:
for (i = 0; i < fieldlen; i++){
stored[i] = str[*offset + *curpos + i];
}
str[*offset + *curpos] = key;
for (j = 0; j < fieldlen; j++){
str[*offset + *curpos + j] = stored[j];
}
After writing it, I realized that there's probably a more efficient way of doing this, but I couldn't think of it.
Chi figured out a way. He decided to go
backwards. Hunh. I totally didn't think of that. Basically what he did was shift each element one over, one by one, backwards, through a for loop. Cool stuff. It's more efficient because it eliminates an extra for loop!
for (i = maxdatalen; i < ((*curpos) + (*offset)); i--){
str[i] = str[i - 1];
}
I noticed a lot of people were having trouble with the pointers we were using like *offset and *curpos. I can't remember which sections of code people were using them for (I think it was the flags and whatnot), but they weren't using the little "*" so their values never updated. Some tried having some variables with and some without "*", and that threw the compiler off and gave a bunch of errors.
There was also something that was bothering me last week. A line in the
Assignment 1 specifications for
io_edit had a little line in italics that read:
If any of insertmode, curpos or offset is NULL then a local integer variable will be used instead. If local variables are used for any of insertmode, curpos, or offset, the default values will be 1, 0, and 0 respectively.Nifty little line here. I remember trying to figure out how to do this, and I was ... actually it's almost 4AM and I really don't remember anything at this time of the day ... but yeah, I couldn't figure it out! I do remember struggling with it however. I knew that I needed local variables. So I set them: int i_mode, int c, int o (Yes, creative. I know.) But how do I actually get them to update?? A question for
Fardad for sure. Good thing I asked. He pointed me into the direction of pointer use and how pointers point to the information stored(No pun intended - Oh who am I kidding?). If you use an "&", the pointer would then point to that variable's address! After a bit of tinkering to fully understand it, I came up with:
offset = &o;
curpos = &c;
insertmode = &i_mode;
Works perfectly!
Now, for the tests that we had to run, I realized that a lot of things weren't too clear. Especially with things like the ESCAPE key. The Escape key, if IsTextEditor is 1, should just set done = 1. If IsTextEditor is 1 however, your program needs to
revert to the original state. Meaning everything you changed when you entered io_edit needs to be reset! I had to get someone from irc to help me out with that one. There were others but my tired eyes can't stay open and my brain isn't functioning either.
I also noticed on
Istessema's blog as I was writing this has a peculiar error that I also ran into:
/tmp/ccbFpdaq.o:
In function `
io_display‘:
ciol.c:(.text+0×16b): undefined reference to `putch’
collect2: ld returned 1 exit status
The solution for this is to change the putch to io_putch. Simple as that. io_putch calls putch!
Anyways, right now I have to figure out Borland. It doesn't work at all. I remember someone saying that we had to change something with the includes (windows.h and conio.h)... but I couldn't remember what it was. I wish I logged stuff on irc. Also, I looked through the green book and I didn't find anything in there either. What I did find was on
Denny's blog he pointed out that any function that didn't have any parameters had to have (void) in it. Else it would give more warnings. So I've cut all of those out of my ciol.c. And there's still more! So many more that my console window will not show it all despite me setting the buffer to 100 lines!! Here are the errors I caught(Best of all they're mostly in testmain which is provided to us!):
Warning W8065 testmain.c 122: Call to function 'test7' with no prototype in function main
Warning W8065 testmain.c 126: Call to function 'test8' with no prototype in function main
Warning W8065 testmain.c 129: Call to function 'test9' with no prototype in function main
Warning W8065 testmain.c 133: Call to function 'test10' with no prototype in function main
Warning W8065 testmain.c 140: Call to function 'io_clrscr' with no prototype in function main
Warning W8065 testmain.c 152: Call to function 'io_getch' with no prototype in function main
Warning W8065 testmain.c 153: Call to function 'io_end' with no prototype in function main
Warning W8004 testmain.c 72: 'ok' is assigned a value that is never used in function main
Warning W8065 testmain.c 171: Call to function 'io_clrscr' with no prototype in function test10
Warning W8065 testmain.c 182: Call to function 'io_getch' with no prototype in function test10
Warning W8065 testmain.c 184: Call to function 'io_clrscr' with no prototype in function test10
Warning W8065 testmain.c 186: Call to function 'Yes' with no prototype in function test10
Warning W8060 testmain.c 205: Possibly incorrect assignment in function resetStr
Warning W8065 testmain.c 290: Call to function 'io_getch' with no prototype in function pause
Warning W8065 testmain.c 301: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 314: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 328: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 343: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 357: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 371: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 385: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 399: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 413: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 427: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 442: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 450: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 457: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 465: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 472: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 480: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 487: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 495: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 502: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 510: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 517: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 525: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 527: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 529: Call to function 'io_getch' with no prototype in function test9
Warning W8065 testmain.c 536: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 551: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 565: Call to function 'io_clrscr' with no prototype in function test9
Warning W8065 testmain.c 580: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 588: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 595: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 603: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 610: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 618: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 625: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 633: 'jump' is assigned a value that is never used in function test9
Warning W8065 testmain.c 640: Call to function 'io_clrscr' with no prototype in function test9
Warning W8004 testmain.c 648: 'jump' is assigned a value that is never used in function test9
Warning W8004 testmain.c 299: 'ok' is assigned a value that is never used in function test9
Warning W8065 testmain.c 661: Call to function 'io_clrscr' with no prototype in function test8
Warning W8065 testmain.c 701: Call to function 'Yes' with no prototype in function test8
Warning W8065 testmain.c 709: Call to function 'io_clrscr' with no prototype in function test7
Warning W8065 testmain.c 749: Call to function 'Yes' with no prototype in function test7
Warning W8065 testmain.c 758: Call to function 'io_clrscr' with no prototype in function test6
Warning W8065 testmain.c 795: Call to function 'Yes' with no prototype in function test6
Warning W8065 testmain.c 799: Call to function 'io_clrscr' with no prototype in function test5
Warning W8065 testmain.c 808: Call to function 'io_rows' with no prototype in function test5
Warning W8065 testmain.c 811: Call to function 'Yes' with no prototype in function test5
Warning W8065 testmain.c 815: Call to function 'io_clrscr' with no prototype in function test4
Warning W8065 testmain.c 824: Call to function 'io_rows' with no prototype in function test4
Warning W8065 testmain.c 827: Call to function 'Yes' with no prototype in function test4
Warning W8065 testmain.c 832: Call to function 'io_clrscr' with no prototype in function test3
Warning W8065 testmain.c 869: Call to function 'io_rows' with no prototype in function test3
Warning W8065 testmain.c 870: Call to function 'Yes' with no prototype in function test3
Warning W8065 testmain.c 880: Call to function 'io_clrscr' with no prototype in function test2
Warning W8065 testmain.c 884: Call to function 'io_getch' with no prototype in function test2
Warning W8065 testmain.c 885: Call to function 'io_clrscr' with no prototype in function test2
Warning W8065 testmain.c 889: Call to function 'io_getch' with no prototype in function test2
Warning W8065 testmain.c 894: Call to function 'io_rows' with no prototype in function test2
Warning W8065 testmain.c 894: Call to function 'io_cols' with no prototype in function test2
Warning W8065 testmain.c 909: Call to function 'io_cols' with no prototype in function test2
Warning W8065 testmain.c 909: Call to function 'io_rows' with no prototype in function test2
Warning W8065 testmain.c 933: Call to function 'io_clrscr' with no prototype in function test2
Warning W8065 testmain.c 937: Call to function 'Yes' with no prototype in function test2
Warning W8004 testmain.c 884: 'key' is assigned a value that is never used in function test2
Warning W8065 testmain.c 942: Call to function 'io_clrscr' with no prototype in function test1
Warning W8065 testmain.c 949: Call to function 'io_rows' with no prototype in function test1
Warning W8065 testmain.c 951: Call to function 'io_cols' with no prototype in function test1
Warning W8065 testmain.c 953: Call to function 'io_rows' with no prototype in function test1
Warning W8065 testmain.c 953: Call to function 'io_cols' with no prototype in function test1
Warning W8065 testmain.c 955: Call to function 'Yes' with no prototype in function test1
Warning W8065 testmain.c 961: Call to function 'io_clrscr' with no prototype in function welcome
Warning W8065 testmain.c 971: Call to function 'Yes' with no prototype in function welcome
Warning W8065 testmain.c 977: Call to function 'io_getch' with no prototype in function Yes
Warning W8065 testmain.c 982: Call to function 'io_getch' with no prototype in function Escape
Error E2228 testmain.c 982: Too many error or warning messages in function Escape
*** 1 errors in Compile ***
ciol.c:
Warning W8065 ciol.c 177: Call to function 'io_clrscr' with no prototype in function io_end
Warning W8019 ciol.c 352: Code has no effect in function io_edit
Warning W8004 ciol.c 290: 'len' is assigned a value that is never used in function io_edit
Warning W8004 ciol.c 286: 'i' is assigned a value that is never used in function io_edit
Warning W8004 ciol.c 604: 'i' is assigned a value that is never used in function io_displayMenuItem
Warning W8057 ciol.c 666: Parameter 'format' is never used in function io_menuItem
Warning W8057 ciol.c 666: Parameter 'len' is never used in function io_menuItem