Ahh nice, an easy solution. Thanks guys!
Type: Posts; User: Mentallic
Ahh nice, an easy solution. Thanks guys!
I have an array of strings char string[n][MAX_FILE_NAME] and in each string I want to initialize it with the name of a bunch of files I have. string[0] should be "txt_0", string[1] = "txt_1" etc.
...
I tried that at first and it didn't seem like it worked, but it was actually a problem I had elsewhere that made me think it failed. Thanks for helping me notice it.
I have a linked list where each node contains a pointer to a string, I'm treating the linked list as a text file and each node/string contains each line in the text file.
I have all of that...
Oh I see. The new line isn't a big deal for me in this case, I was just worried that I was doing something wrong.
Right, thanks. I'll go ahead and add
text[0] = '\0'
after I malloc.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_COL 70
#define MAX_ROW 20
int main(void) {
FILE *fp;
The missing line that you pointed out was the problem... That's pretty embarrassing haha :redface:
That diff tool is a good idea. Thanks!
I made an attempt to shorten my code in a particular function because it had lines that repeated themselves.
The function that has duplicate lines but works
static Line newLines (char text[])...
Derp... I've made that mistake in the past as well. It's just hard to override some common sense sometimes. The fact that I let list = NULL and then curr = list, and while I gave room to list on the...
Well spotted.
In the function that's causing the seg fault
static Line newLines (char text[]) {
Line list = NULL, curr = list;
int lineCount = 1;
int length = strlen(text);
Due to popular criticism, I removed the asserts :biggrin:
I'm having a seg fault that I just don't understand...
//Compile: gcc -Wall -Werror -O -o text textbuffer.c tests.c
#include...
Oh right, I totally forgot about the ampersand.
I'm all for learning better coding practises, unless it deviates from my professor's style. I appreciate your tips but changing it would just...
Ok cheers for that :)
I have a string that contains a various number of lines which are each separated by \n and so what I want to do is to put each line into a node in a linked list.
The relevant sections in my code...
That makes perfect sense! Thank you tabstop.
edit: Just one more thing. If I set the pointer to the struct to NULL, then I've basically lost the position of the struct in memory, hence I've also...
I'm working on an assignment that handles text and operations on the text. What I have so far is
//tests.c
//Compile: gcc -Wall -Werror -O -o text textbuffer.c tests.c
#include <stdio.h>...
I think I see what it's doing. It's going to be consuming each character in the input buffer including the new line character, but breaks from the while loop when that happens so it stops waiting for...
I see. Sadly, I don't know how to do that.
Thanks, I noticed it too, and I would've spotted it even earlier if I used the -Wall flag :)
I'm trying to create a connect four game, but I've ran into a problem while trying to read valid user input.
// 4 in a row game
#include <stdio.h>
#include <stdlib.h>
#define NUM_ROWS 6...
Thanks Hodor, that makes a lot of sense now.
If I use
enum BOOL {FALSE, TRUE}
then I'm guessing FALSE is replaced with 0 and TRUE with 1, right? But do I also need to add this enum line...
That won't do because I'm going to be using the numbers I scanned in not only in the function, but later on outside of the function too.
Yes, thanks for spotting that.
I'll be using it a...
I want to scan numbers in from within a function, but have access to them in main, so I tried using pointers to do so:
// Path Of Exile socket colours simulation
#include <stdio.h>...
But I don't know how many strings I'll need to put into messages. If I make it messages[n] then I'm set on having only up to n strings, but may need more.
But my assignment has a .h file...
Does the array have room? The messages[] that doesn't actually have a size associated with it at compile time is confusing me. How much room is there? Can I put as many strings in as I want?
...
I'm unsure to be honest. I'm working on the terminal that comes with ubuntu and I'm using gcc with no flags to compile the file.
My current code isn't the issue (at least it shouldn't be). I'm...