Thank you for your advice concerning array of structures.
However, I would like to ask if it is possible to keep the initialization the way I have shown, one line per node. It was not shown in my...
Type: Posts; User: Pole
Thank you for your advice concerning array of structures.
However, I would like to ask if it is possible to keep the initialization the way I have shown, one line per node. It was not shown in my...
As the topic title says - I have a problem with
The code:
#define LANG_EN 0
#define LANG_PL 1
#define LANGUAGES 2
const char *const message[][LANGUAGES] = {
Thank you for the suggestion. However, it does not seem to work on my PC.
My code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
Thank you for your help, but it is not applicable for my idea. I am running the app on a microcontroller.
------
I have an idea - is array of string arrays applicable and would solve the problem?
Hello, I have created a simple program for a microcontroller. I have created a menu displayed on an LCD.
Now I want to add the possibility of choosing a language version, so that a group of strings...
Hello Dear Community of cprogramming.com!
I have a following problem - I wrote a simple add_record function using structures (here is my main file):
// Exercise1.cpp : main project file.
...
I did calloc (with a random value - I've chosen 100) so that I can initialize data->word = ""; data->occ = 0; . This was suggested to avoid SIGSEGV caused by strcmp in search function with a...
EDIT: I can't edit my post so I present new approach to my code. In gdb I can see that the problem is with iterating my ptr pointer. The program finds words properly, but ptr doesn't change to that...
I don't know how to represent the end of constantly updated array of structures.
My search function must have prototype struct abc *find(char *word)
so I can't pass that parameter.
OK. So following Your advice I've made:
words *findword(char *word)
{
words *ptr = data;
for (ptr; /*what to put as stop cond. */; ptr++) {
if ((strcmp(word, ptr->word))...
strdup is from <string.h>
I've only shown parts relevant to the problem. getword works fine, no need to make a mess in the post and extend it to hundreds of lines of code.
getword returns char *
The snippets below are from my program that gets words, then prints them with the number of occurences.
It works almost fine - it "forgots" that that entry has been saved before and does NOT...
After doing what You advised - I get a segfault
Here is the change (rest the same as on the previous page), only changed second while loop in main.
while (((number_next = getnum(infile, base)) !=...
So I guess I should add
((feof(infile) == 0) || (number1 = getnum(infile, base) != NULL )) number1 instead of number 2, as @oogabooga said.
valgrind -v gives me no errors, so I guess no memory leak there.
Fixed, thank You.
But, condition
(feof(infile) == 0) is not always true. What if a file would be empty?
Yeah, I got it...
@Matticus - I got it working, thank You!
@oogabooga I quoted your post, why did you suggest that change in while condition? Is the one presented in the code in the first post prone to some...
I did as You advised. However, now program hangs after invoking, and I have to press Ctrl+C to stop it.
I only changed main(), posting it below:
int main(int argc, char **argv)
{
FILE...
If I decide to store it in an array that would be a two-dimensional array. Then how to pass those strings, two at a time, and keep the result of the previous operation as one of the parameters passed...
Thanks for reply. I have another question though. How to implement contnuous search and assignment for new numbers read from file. I mean, firstly assign
number = getnum(infile, base) and then how...
OMG oogabooga You helped me a lot!
I'd never get to that, I was expecting memory management is incorrect, and I was looking into it mainly.
The program is supposed to run as
./name input.txt...
Hello, I have a problem with an "add calculator".
Valgrind reports no memory errors, no errors from compiler but the program doesn't show any output despite the printf - "Result is zero".
All...
Yeah, but which line assigns '5' to s[0] ?
I appreciate Your help very much, however again it doesn't work properly. At least now, there's no segmentation fault ;)
isdigit seems to be not detecting numbers, and even though I clear the...
So apparently it is the other way round (than I thought), 6 overwrites \0 which was previously there at s[1] created by line 84?
Big thanks, now I understand every thing You had written about.
However I still wonder about that - "What if 567 is entered ? 5 would be array[0], 6 in array[1], 7 in array[2] and 6 from array[1]...