Jump to content
Can't remember your login details? Read more... ×


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Serf

About Fury52

  • Rank
  1. Fury52

    Trying to understand how this code works.

    Okay, here's what i still don't get. Hints won't do it for me, there's not enough time from now to my exam. What i don't get: 1. What the !*s refers to. Logical not *s, means that when *s is not pointing to 0, right? 2. What happens in the overall code. It goes into a recursive loop, and each time it does that it goes to the next character in the string. But what does it do? How does it reverse the string? How does recursively going to the next character in the string reverses the string? This is a standard question, and at this rate i'll fail this exam. Again. Adding 1 to that address is like saying 124 smith st, so we refer to the next 'house' (character) in the 'street' (string), yes? After we add one, we do SOMETHING. I don't know what that something is. I don't even know how recursion is supposed to reverse the string. As far as i see, all it does is keep going to the next character until the end. Then it outputs the string, and somewhere BETWEEN those two, it somehow reverses the string. Very confused.
  2. Fury52

    Trying to understand how this code works.

    Yes, but s is referring to the address of the input string, so s + 1 would be the next block in that string, right?
  3. Fury52

    Trying to understand how this code works.

    So until it points to 0...that means until it points to the end of the string? In other words, keep going until the character reaches the end of the string... Okay, i have the answer, and it in fact reverses the string. Now, it keeps going until the pointer reaches 0, and then it stops and prints out the character...or something. But if it moves each address by one space, then isn't the characters after the k lost? Incredibly confused, maybe another hint? I'll get there.
  4. Fury52

    Trying to understand how this code works.

    I see. Since *p actually refers to the object, p is referring to the ADDRESS of the object and so f(s + 1) means moving the character up one place in the array, and continue doing that until a certain condition is met. Although, i still don't understand what !*s means. Already knew that ! is the logical NOT operator, but what would the condition !*s mean (logical not *s) mean exactly?
  5. Okay, say i'm given this code and i'm asked to write out it's exact output: #include <stdio.h> void f( char *s ) { if( !*s ) { return; } f( s+1 ); putchar( *s ); } int main(void) { f("kernighan"); putchar(’\n’); return 0; } I don't get it at all, but i don't really want anyone to just explain to me step by step how this works. Hints and little pointers here and there would be nice. There's a few things that i'm completely unsure of. Namely: 1) What does the condition !*s mean? *s refers to the string, which is an array of characters. So then what on earth would !*s mean? Is it a limiter of some sort? 2) Is return; the same as return NULL; ? 3) does f(s+1) mean every character in that array is increased by a value of 1? So then for example 'k' becomes 'l' and so on? (I've checked it in the compiler, so i know it DOESN"T, but is my train of thought anywhere close to the answer?) At first i thought that it just takes each character in that array and increases it by 1. If that character just so happened to be equal to !, then it would just cease execution. Beyond that however, i'm completely stuck. Help?
  6. This isn't a normal linked with a specified number of nodes. This is a linked list where n number of nodes are generated depending on an email file, and with each message being put in an individual node. My problem is deleting a node in the linked list. The node to be deleted will be whatever the pointer currMsg is pointing to. My idea is this: Have each of the node keep pointing to the next one, have a pre-defined, given (i.e, i was GIVEN said function without knowing how it works) function create the n number of nodes While it's doing so, when it reaches the node that currMsg is pointing to, have that node point to a temp node (called temp), though an if condition. Have the rest of the node continue churning out the nodes. When that's finished, delete the pointer to temp ( free(temp) ) Print the list through another pre-defined,given function. I see a problem, i think, which is that the link will be broken. Problem is, since the node will be made in a while loop, i cannot see how i could link the n-1th node to the n+1th node while skipping the nth node (where the nth node is the node to be deleted) Am i actually right? If not, why am i wrong, and is there a solution to my problem? Oh, and my problem is deleting a node in the MIDDLE of a linked list. And the front of the linked list come to think of it.
  7. Oh, and i only know C, so i can't actually read any of that code. Sorry. I''m assuming C++ is the industry standard? I though C was more widespread.
  8. This is just on my assignment. Due Sunday, still not nearly there. But we're making progress, thanks for the help so far everybody. =) Okay, so my question. The given code gives me a switch-case condition with some of the conditions already stated. For one of the stages of my assignment, i just want to know if we can create a switch-case where it detects that if the user inputs an integer, it then moves to this block of code. This is what i've done: //given code switch © { ............. ............... ................ //my code case: '<%i>': //more of my code break; Is this possible? If it isn't, then how might i go about make a switch-case condition which can detect a user's input in the form <%i>? How about: int k; case (scanf ('%i',&k)):?
  9. Okay after a bit of research and practice, i *think* i'm beginning to get the hang of this linked list business. But i have a question. How exactly do you make the linked list so that it remembers the first node while you create n number of nodes? Is it possible for someone to outline the process in a step by step process? (i.e, first you make the typedef structure, then you make the head nodes, then you link this node to that....etc,etc)
  10. Should have probably mentioned that i only know how to program in C, and the assignment has to be written in C. My bad.
  11. I have an assignment, giving me a truckload of trouble. It requires the use of a linked list. I won't go into the specifics of the assignment here, only that it requires me to use linked lists and to continually make linked lists until a certain given function (i'm not told how this function works, only that it extracts messages from this file, stores it and creates a pointer to it) returns null, which it will. I don't fully get linked lists. I know they're structures and that they have a pointer pointing to itself. I know that to create a linked list you create another node and link the first node to that list. For more nodes, you need to maintain a link to the first node and link the second with the third..the third with the nth...and so on. Problem is, i don't know how many nodes to create. I need to create a while loop it seems, on the condition that the function, called getnextmessage(fp) !=NULL. I don't know how to create n number of nodes. And if i don't know how to create n number of nodes, i'll get below the requisite mark for the assignments component of my course and will be given an automatic fail. fml. Anyone out there whose willing to help? It'll be so appreciated i can't even begin to describe what i'd be willing to do.
  12. I've been given an assignment that's REALLY giving me some serious trouble. Please help, even if what i ask is completely stupid (it's guaranteed to be) void printEmailSynopsis( enum priorityCode priority, enum statusCode status, int msgNum, char *from, char *date, char *subject); Say i'm given this function declaration. All i'm told is that this function prints out the synopsis of an email. I do not know the inner workings of this function. This is all i'm given. This function declaration is given in a header file. My main c file refers to this header file. How exactly, do i refer to this function? I've tried only to get error messages such as 'error: incompatible type for argument 1 of 'printEmailSynopsis' and warning messages such as: arning: passing argument 5 of 'printEmailSynopsis' from incompatible pointer type'. It's incredibly annoying. Can someone please outline how i'm to refer to this function in the main c file? It may seem unbelievably basic and stupid, but at least it might get my head around the given code. Thanks in advance.
  13. Bear in mind that I have to program in C, although i understand what you've written there.
  14. They're defined separately.In fact, LINE 1 and LINE 2 are separate functions.