No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
I've learned to write bytes from a file by reading the entire file into a character array and then writing them out to another file using fwrite. Of course, my teacher told me this is both wasteful and a file might not fit into memory, so I should use another … | |
I've never written byte variables on my unix shell before, so I don't know if it works or not. I'd been using unsigned ints to get hex numbers as input but I was having trouble with what my input actually was. My friend told me to use byte variables instead … | |
What way(s) can I reread the same file in C? I've only been able to find C++ tutorials. I tried: [code] fclose(infile); infile = fopen(argv[1], "r"); //error checking [/code] but this code didn't go to the beginning of the file. | |
I have an assignment I'm working on in C but I didn't want to ask for any code specifically. I just wanted to ask about the methods to use. The program reads a text file where it tells you the number of values to hash. The hash function is completely … | |
I was wondering which method I should use to declare a 2D array. First, I was going to declare a 2D array of char arr[15][100]. In each text file, there's a number on the first line, and that displays how many columns are in the text file, so I would … | |
If I know the sizes I'm using, I can declare the array as: [code]char arr[20][20];[/code] Is this correct? Well, I want to know how to insert a full string into the array of strings. I thought it might be: [code]fscanf(infile, "%s", *arr[i]);[/code] but this line gave me the error "warning: … | |
This is a little program I'm writing to refresh my knowledge of C and I know it's wrong, but everything I've tried in order to fix it isn't working. [code] #include <stdio.h> #include <string.h> int main() { int const STR_LENGTH = 255; char str[STR_LENGTH]; int n=0,i=0; printf("Please enter a word: … | |
If I have a struct defined as [code] struct node { char *data; struct node *next; }; typedef struct node* nodePtr; nodePtr newNode; ... int main(void) { newNode = (nodePtr *) malloc(sizeof (nodePtr)); //dynamically allocate memory if(newNode == NULL) { printf("Error: could not allocate a new node\n"); exit (1); } … | |
Say I have [code] #include<iostream.h> int tempNum; struct node { int data; struct node *next; }; struct node *newNode = NULL; int main(void) { tempNum = 5; newNode->data = tempNum; //gives seg fault } [/code] *edit - I'm trying to add tempNum to the very first node. I haven't worked … | |
Back to where I was, now I'm learning how to use fgetc properly. Does fgetc read in a character? If so I can't find my error in my code and I'm getting a a segfault. Can you help fix it and explain why it doesn't work? Thanks [code]#include<stdio.h> //declare variables … | |
I'm getting a segmentation fault when I try to run my program. It's probably because I'm not referencing my pointer to a string right, or dereferencing whatever it's called. This is basically what my code looks like. [code] #include <stdio.h> FILE *myFP; char filename[20]; char *pstr = finlename; void func(char … | |
I want to store a byte from fread as type char, and then be able to perform comparison operations on that byte as an int. I have [quote] int num; char buffer; num = fread(buffer, 1, 1, myFP); [/quote] and I'm sure it's not right. | |
I'm better at C++ than C right now and I forgot how to use arrays in functions from main. I want to do something like [quote]void fileReader(infile[] ); [/quote]. Is infile supposed to be a pointer and if so how is it written? | |
Also argument 2 makes integer from a pointer with a cast. One argument is a struct declared in an included library. It's declared like: [code]struct pixelst *lzwArr; lzwArr = (struct pixelst *) malloc(pixels); // pixels is an int[/code] the second argument is an unsigned int 2D array. It's used in … |