Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ShinAli
May 2, 2003

The Kid better watch his step.
Not a C question really but I wanna know how to set up vim to be a pretty good IDE for C programming.

I saw a website out there describing out to set up vim for python, and had all these neat things like a debugger, code completion, COLOR, and so forth. I'm starting to like vim (even though I don't have a handle on all the commands and stuff yet), and since I'm going to be using vim for the entire semester, I'd like to configure it a bit for C.

You guys got anything?

Adbot
ADBOT LOVES YOU

ShinAli
May 2, 2003

The Kid better watch his step.

haywire posted:

Where should I start? Are there any good goon recommended free tutorial sites I can busy myself with before I sink money into a good book?

Right now I'm going through the Accelerated C++ book as all others really piss me off and don't move fast enough for me. It does get a little "THIS HOW YOU PRINT "HELLO WORLD" GEE WIZ" in the beginning but it picks up the pace a little faster and teaches you actually useful things first, then goes deeper into them in the later chapters. I'm going to skim through Thinking in C++ vol 1 since I think Bruce knows what he's talking about, and try to look into vol 2.

I'm also taking a course called "Advanced Programming" that goes through everything in the beginning programming courses up to Data Structures, but this time in C. I like my prof. since he's making me get off my lazy rear end and learn some *nix.

ShinAli
May 2, 2003

The Kid better watch his step.
Got a quick question about pointers in C.

Right now I got a struct with a growing character array which would contain multiple strings. Every time I run out of space (when adding strings), I realloc the struct. This keeps it in one memory block.

I also have a string (or character pointer) array which the elements point to individual strings in the character array of the struct. The obvious problem being is that when the character array struct gets reallocated, the pointers in the string array get outdated.

To update them, I search the outdated string array for the base pointer of the old struct (I just compare all pointers via ptr1 < ptr2 in a loop and which ever is the smallest, I figure is the base pointer). The idea I have is to subtract the old base pointer with every char pointer in the array, then add the base pointer of the realloc'ed struct character array to every element.

I'm not sure if I'm allowed to do that, though. Do I cast the pointers to some other type, do what I need to do, and cast it back to a pointer?

ShinAli
May 2, 2003

The Kid better watch his step.
hey guys C/stdio question. there is this function:

code:
unsigned char readbyte(FILE *f)
{
  unsigned char d0f_loc;
  FILE * lfi;
  lfi = f;
  fread(&d0f_loc,sizeof(unsigned char),1,lfi);
  return d0f_loc;
}
... which reads one byte from the passed in file, and returns it. Two different FILE pointers are used with this function. The first file is read in and stored into memory, then it's file pointer is closed. The second file is fseek'd to the end, got the file size using ftell, then I did another fseek to the beginning. The file is read intermittently until I get to the end of file.

Or at least that's what supposed to happen. I get a segmentation fault on a machine with Ubuntu on the fread line after it tries to read the 10th byte (refers to iofread.c file in line 43 I think, but the machines didn't have the source for the stdlib they use). I don't get it because it reads in the first file in it's entirety just fine. The weirder thing is it works fine on my Macbook Pro/C2D/OSX-1.5.7.

ShinAli fucked around with this message at 15:19 on Aug 5, 2009

ShinAli
May 2, 2003

The Kid better watch his step.

ShoulderDaemon posted:

No, it doesn't. It completely ignores the passed in stream, attempts to read a single byte from an undefined stream, and returns a byte which may be the result of such a read, but may just be undefined as well because the read isn't checked for success.

Sorry, typo. There was supposed to be a lfi = f after FILE * lfi.

As for the rest of your comments, I was trying to express what happens in general in the program and how the function is used with it.

But you can chillax, I figured it out. For some reason this guy doesn't know how to handle his pointers and the FILE pointer got decremented somehow.

ShinAli fucked around with this message at 23:18 on Aug 5, 2009

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply