Conversation you should not have with a third year CS student

The following is an actual conversation over AIM with a third-year Computer Science student at UF. The material discussed is normally learned freshman year. This student would probably not be able to pass the Foundation Exam at UCF, and consequently would not be allowed to continue studying Computer Science at UCF. Note that some of the lapses in time are from me walking away from the computer in total disbelief at the question asked. My roommate (a CS student like me) also pitched in at one point. Read at your own risk.

(9:17:20 PM) UF CS Student: why are strings not data trypes in C
(9:17:26 PM) UF CS Student: its making me frustrated :(
(9:21:20 PM) Me: char*?
(9:21:41 PM) UF CS Student: I have to implement pipe
(9:21:43 PM) UF CS Student: in a shell
(9:22:04 PM) UF CS Student: I know how it works… just can’t get the commandInput split into the arguments i need for the execvp
(9:22:13 PM) UF CS Student: cause the string maniuplation is driving me insane in c
(9:22:23 PM) Me: char*?
(9:22:26 PM) UF CS Student: what about it?
(9:22:37 PM) UF CS Student: I know its an array of characters..
(9:22:38 PM) Me: strings are character arrays
(9:22:43 PM) UF CS Student: but its just the maniuplation of it
(9:22:48 PM) UF CS Student: like strtok
(9:22:53 PM) UF CS Student: to find the |
(9:22:58 PM) UF CS Student: and I wnat the stuff before the |
(9:23:00 PM) UF CS Student: and the stuff after teh |
(9:23:18 PM) Me: make a loop?
(9:23:26 PM) UF CS Student: yes I know i have it
(9:23:32 PM) UF CS Student: I have a method taht gets the arguments
(9:23:38 PM) UF CS Student: but I am trying to access tehm
(9:23:48 PM) UF CS Student: but strtok returns it into a single variable
(9:23:50 PM) UF CS Student: not individual ones I want
(9:24:07 PM) Me: don’t use strtok then
(9:24:14 PM) Me: or learn2use it
(9:24:33 PM) UF CS Student: … what else is tehre taht lets me split a string in C????
(9:24:36 PM) UF CS Student: if not strtok
(9:24:42 PM) Me: a loop
(9:25:00 PM) UF CS Student: so I can tell it to split it and stop at |
(9:25:13 PM) UF CS Student: and then give me the stuff before and after |
(9:25:16 PM) UF CS Student: in seperate variables?
(9:27:00 PM) Me: yes
(9:37:37 PM) UF CS Student: what is the difference between doing tihs
(9:37:52 PM) UF CS Student: char myString[100] = “blah blah”
(9:38:07 PM) UF CS Student: myString[0]
myString
(9:38:12 PM) UF CS Student: what is teh difference if I use teh [] or not?
(9:38:13 PM) UF CS Student: do you know?
(9:40:06 PM) Me: hold on I had to walk away to make sure I read that right
(9:40:25 PM) Me: whats the difference between referring to a single character and the entire array?
(9:40:29 PM) UF CS Student: eyah
(9:40:33 PM) UF CS Student: in C
(9:42:01 PM) Me: read about pointers
(9:42:03 PM) Me: please
(9:42:06 PM) Me: learn pointers
(9:42:16 PM) Me: then come talk to me
(9:46:21 PM) UF CS Student: i guess I am not understanding how the [x] x value points
(9:46:31 PM) UF CS Student: because i thought it was the character in the string
(9:46:39 PM) UF CS Student: so 3 would be the third character
(9:46:44 PM) Me: fourth
(9:47:01 PM) UF CS Student: so 0 points in front of the string?
(9:47:12 PM) Me: it points to the first character
(9:47:15 PM) Me: or more
(9:47:27 PM) Me: it’s the character at the first position
(9:47:56 PM) Me: pretty much myString[0] results in a char type
(9:48:05 PM) Me: myString returns the entire array
(9:48:17 PM) Me: so it
(9:48:21 PM) Me: it’s like char*
(10:16:47 PM) UF CS Student: how can i loop thru an a char arrray
(10:21:02 PM) Me: with a loop
(10:21:40 PM) UF CS Student: know that
(10:21:47 PM) UF CS Student: but I am saying waht fucntions can I use
(10:22:37 PM) UF CS Student: use a counter and just go thru it >> hmm
(10:23:27 PM) Me: you know how in a for loop you declare some sort of iterator?
(10:23:47 PM) Me: like for (i = 0; blah; i++)????
(10:23:55 PM) Me: use that shit
(10:24:02 PM) Me: mystring[i]
(10:24:10 PM) Me: that is the offset from mystring
(10:24:24 PM) Me: mystring being the pointer to the start of the string
(10:24:30 PM) Me: string meaning char[]
(10:30:13 PM) UF CS Student: myshell.c:66: warning: assignment makes pointer from integer without a cast
(10:30:42 PM) Me: c&p
(10:31:02 PM) UF CS Student: char *firstHalf[100];
int j = 0;
for (j = 0; j < strlen(commandLine); j++) {
if (commandLine[j] == ‘|’) break;
firstHalf[j] = commandLine[j];
}
printf(“first Half: = \”%s\” \n”, firstHalf[0]);
(10:31:15 PM) UF CS Student: I guess I can’t put it where array equal array
(10:31:23 PM) UF CS Student: I need to getChar or osmething?!?
(10:31:38 PM) Me: you assigned 100 pointers btw
(10:31:42 PM) Me: just fyi
(10:31:54 PM) UF CS Student: so I just need 1?
(10:31:55 PM) UF CS Student: I dont get it
(10:32:14 PM) Me: char *firstHalf[100]; -> char firstHalf[100];
(10:32:23 PM) UF CS Student: so I shouldn’t use a *
(10:32:37 PM) Me: no
(10:33:06 PM) UF CS Student: thunder:254% gcc myshell.c
thunder:255%
(10:33:10 PM) UF CS Student: thats always soothing
(10:33:13 PM) UF CS Student: when there are no errors :(
(10:33:51 PM) UF CS Student:
$ test|
found the PIPE!!
test|
first Half: = “test”
(10:33:56 PM) UF CS Student: wow I’m surpruised that wroked
(10:33:57 PM) UF CS Student: lol
(10:34:37 PM) UF CS Student: but its still failing to find teh spaces
(10:34:41 PM) UF CS Student: if I put a space its not doing it./..
(10:34:52 PM) UF CS Student: is there something about a space and the way its stored in teh char array taht breaks it??
(10:38:02 PM) Me: pastebin your entire code
(10:38:51 PM) UF CS Student: http://pastebin.ca/1940224
(10:41:04 PM) UF CS Student: ultimately all I want to do is be able to take first stuff before pipe and pass to execvp or execlp … vp accepts teh char array
(10:46:56 PM) Me: rtfm http://www.cplusplus.com/reference/clibrary/cstring/strtok/
(10:47:04 PM) Me: you lose your original string

Share

Tags: , , , ,
| September 16th, 2010 | Posted in College, Technology |

Leave a Reply