I'm supporting some c code on Solaris, and I've seen something weird at least I think it is:
char new_login[64];
...
strcpy(new_login, (char *)login);
...
free(new_login);
My understanding is that since the variable is a local array the memory comes from the stack and does not need to be freed, and moreover since no malloc/calloc/real...
i am trying to get some data from the user and send it to another function in gcc. the code is something like this.
printf("Enter your Name: ");
if(!(fgets(Name, sizeof Name, stdin) != NULL)) {
fprintf(stderr, "Error reading Name.\n");
exit(1);
}
However, i find that it has an \n character in the end. so if i e...
I am writing a small C application that use some threads for processing data. I want to be able to know the number of processors on a certain machine, without using system() & in combination to a small script.
The only way i can think of is to parse /proc/cpuinfo. Any other useful suggestions ?
...
I'm looking to replace our current model (written entirely in Tcl (please don't even start)) with a new model based around an SQL (sqlite) database, and I'm looking for books/articles giving advice on how one goes about designing a DB schema as well as the model interface around it.
I've been reading questions about updating bad DB sche...
For instance:
void* sdl_library = dlopen("libSDL.so", RTLD_LAZY);
void* initializer = dlsym(sdl_library,"SDL_Init");
Assuming no errors, initializer will point to the function SD_Init in the shared library libSDK.so.
However this requires knowing the symbol "SDL_Init" exists.
Is it possibly to query a library for all its symbols? E...
Can somebody explain me lambda expressions & what they can be used for. I have googled for it & have a rough idea. most of the examples give c# code. How about lambda expressions in plain old C...?
...
I'm implementing a memory pool in C for a real time application. A container data structure is used by the real time thread of the program to process a specific type of data which it needs to add and remove from the container. The implementation of the container is designed so each instance has its own personal memory pool. (Although the...
i have a string of the format "ABCDEFG,12:34:56:78:90:11". i want to separate these two values that are separated by commas into two different strings. how do i do that in gcc using c language.
...
I'm testing this code, but doesn't work, it always says that an error occurred :S
int main(int argc, char **argv) {
FILE *file_pointer;
file_pointer = fopen("text.txt","r");
if(fseek(file_pointer, 0, -1)) {
puts("An error occurred");
}
else {
char buffer[100];
fgets(buffer, 100, file_pointer);...
void cabclh(){
FILE *fp;
char *val, aux;
int i=0;
char *result, cabeca[60];
fp=fopen("trabalho.txt","r");
if(fp==NULL){
printf("Erro ao abrir o ficheiro\n");
return ;
}
val=(char*)calloc(aux, sizeof(char));
while(fgetc(fp)=='\n'){
fgets(cabeca,60,fp);
prin...
In the following example c code, used in an Arduino project, I am looking for the ability to get the size of a specific byte array within an array of pointers to bytes, for example
void setup()
{
Serial.begin(9600); // for debugging
byte zero[] = {8, 169, 8, 128, 2,171,145,155,141,177,187,187,2,152,2,8,134,199};
...
Greetings,
My project structure is as follows:
\- base (C static library)
callbacks.h
callbacks.c
paint_node.c
.
.
* libBase.a
\-app (C++ application)
main.cpp
In C library 'base' , I have declared global-function-pointer as:
in singleheader file
callbacks.h
#ifndef CALLBACKS_H_
#define CALLBA...
I'm messing around with GTK and glade for the first time, and I've run across a really annoying issue. When I enter text into a TextView, the TextView automatically resizes larger, pushing other widgets away.
This is a really annoying behavior. I do not want my TextView changing size depending on the amount of text within it.
Does anyo...
I'm trying to write a word to a file using this function:
extern void write_int(FILE * out, int num) {
fwrite(&num,sizeof(int),1, out);
if(ferror(out)){
perror(__func__);
exit(EXIT_FAILURE);
}
}
But I get a segmentation fault whenever it tries to run the fwrite. I looked at the man page for fwrite(3) and I feel li...
I'm looking to do a parallel programming project in C (probably using pthreads or maybe OpenMP) for a class. It will done by a group of about four students, and should take about 4 weeks. I was thinking it would be interesting to attack some NP-complete problem with a more complex algorithm like a genetic algo with simulated annealing, b...
Hi all,
I have a .lib file, just wondering what compiler it's from: it begins with "!<arch>" ?
Thanks
...
gcc lovingly throws me this error:
bst.c:33: error: invalid application of ‘sizeof’ to incomplete type ‘struct BSTNode’
What makes BSTnode incomplete? Below are the struct definitions relevant to BSTnode.
struct BSTnode{
struct BSTnode * left;
struct BSTnode * right;
struct hash minhash;
struct hash maxhash;
st...
I am experimenting with lex and yacc and have run into a strange issue, but I think it would be best to show you my code before detailing the issue. This is my lexer:
%{
#include <stdlib.h>
#include <string.h>
#include "y.tab.h"
void yyerror(char *);
%}
%%
[a-zA-Z]+ {
yylval.strV = yytext;
return ID;
}
[0-9]+ {
yylval.intV...
I have written a function that checks if to files are duplicates or not. This function signature is:
int check_dup_memmap(char *f1_name, char *f2_name)
It returns:
(-1) - If something went wrong;
(0) - If the two files are similar;
(+1) - If the two files are different;
The next step is to write a function that iterates through a...
I'm currently trying to optimize the sluggish process of retrieving a page of log entries from the SQLite database.
I noticed I almost always retrieve next entries along with count of available entries:
SELECT time, level, type, text FROM Logs
WHERE level IN (%s)
ORDER BY time DESC, id DESC
LIMIT LOG_...