int main()
{
int p;
scanf("%d",&p);
fun()
{
int arr[p]; //isn't this similar to dynamic memory allocation??
}
}
//if not then what other objective is achieved using malloc and calloc??
//Someone please throw some light :-)
...
I have a trie which I am using to do some string processing. I have a simple compiler which generates trie from some data. Once generated, my trie won't change at run time.
I am looking for an approach where I can persist the trie in a file and load it effectively. I have looked at sqllite to understand how they are persisting b-treebu...
Hello. I am trying to fully understand the process pro writing code in some language to execution by OS. In my case, the language would be C and the OS would be Windows. So far, I read many different articles, but I am not sure, whether I understand the process right, and I would like to ask you if you know some good articles on some sub...
I want to copy a large a ram-based file (located at /dev/shm direcotry) to local disk, is there some way for an efficient copy instead of read char one by one or create another piece memory? I can use only C language here. Is there anyway that I can put the memory file directly to disk? Thanks!
...
I want to use /dev/random or /dev/urandom in C - how can i do it ? I don't know how can i handle them in C, if someone knows please tell me how. Thank you.
...
Hello, given the following code (it's supposed to write "hellowolrd" in a "helloworld" file, and then read the text):
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FNAME "helloworld"
int main(){
int filedes, nbytes;
char buf[128];
/* Creates a file */
if((filedes=open(FNAME, O_CREAT | O_EXCL...
fclose() is causing a segfault. I have :
char buffer[L_tmpnam];
char *pipeName = tmpnam(buffer);
FILE *pipeFD = fopen(pipeName, "w"); // open for writing
...
...
...
fclose(pipeFD);
I don't do any file related stuff in the ... yet so that doesn't affect it. However, my MAIN process communicates with another process through shared mem...
I apologize if this is a subjective or repeated question. It's sort of awkward to search for, so I wasn't sure what terms to include.
What I'd like to know is what the basic foundation tools/functions are in C when you don't include standard libraries like stdio and stdlib.
What could I do if there's no printf(), fopen(), etc?
Also, a...
Well here is my little problem, first my code:
struct alumn {
char name[100];
char lastname[100];
int par;
int nota;
};
typedef struct alumn alumn;
int bubble(alumn **arr, int length)
{
int i,j;
alumn *temp;
for (i=0; i<=length-2; i++) {
for (j=i+1; j<=length-1;j++) {
if ((*arr)[i].nota > (*arr)[j...
I am new to MASM. So the questions may be quite basic.
When I am using the MASM assembler, there's an output file called "Link Map". Its content is composed of the starting offset and length of various segments, such as Data segment, Code segment and Stack segment. I am wondering that, where are these information describing? Are they ta...
I have a string that look something like this:
long_str = "returns between paragraphs 20102/34.23\" - 9203 1232 \"test\" \"basic HTML\"";
Note: Quotes are part of the string.
int match(char *long_str){
char * str;
if ((str = strchr(long_str, '"')) != NULL) str++; // last " ?
else return 1;
return 0;
}
Using strstr ...
Hi,
I am coding up an implementation of Interpolation Search in C.
The question is actually rather simple, I need to use the floating operations to do linear interpolation to find the correct index which will eventually be an integer result.
In particular my probe index is:
t = i + floor((((k-low)/(high-low)) * (j-i)));
where, i,j,...
I am trying to get the user defined global hot key for my application. Here is my application code,
user.rc
CONTROL "", IDC_MHOTKEY, HOTKEY_CLASS, WS_TABSTOP, 91, 86, 68, 14
function.cpp
WORD wHotKey = SendDlgItemMessage(hwnd, IDC_MHOTKEY, HKM_GETHOTKEY, 0, 0);
GLOBAL_HOTKEY= wHotKey;
RegisterHotKey ( NULL, TURN...
I want to write some bogus text in a file ("helloworld" text in a file called helloworld), but not starting from the beginning. I was thinking to lseek() function.
If I use the following code (edited):
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#define fna...
Hi,
I'm learning C and I saw in a book that a function prototype has the form void f() and in the function declaration or in the calling function, the f function takes arguments. Thus In the function declaration we have something like void f(long double y[], long double A) and in the calling function is f(y, A). The function is ...
Is Test Driven Development limited to OO? Or is it possible/useful to use it in conjunction with a procedural language? I have to start a greater project in C the next few weeks and I'm thinking of ways how to the developing.
...
Hi, in a recent project I've come really need the lib tre matching library.
However the project is in php, and there are no php bindings for the library.
I've tried to google how to create an interface for c libs, but all I found was the dl function which seams to load only php extensions.
What am I missing?
...
Hi,
I'm using malloc to make an error check of whether memory can be allocated or not for the particular array z1. ARRAY_SIZE is a predefined with a numerical value. I use casting as I've read it's safe to do so.
long double *z1 = (long double *)malloc(sizeof (long double) * ARRAY_SIZE);
if(z1 == NULL){
printf("Out of memory\n...
What does the last function argument mean in C language?
Please, point to documentation where I can read about it.
void parse_options( int argc, char **argv, const OptionDef *options,
void (* parse_arg_function)(const char*) )
Thanks.
...
I am currently learning C by reading a good beginner's book called "Teach Yourself C in 21 Days" (I have already learned Java and C# so I am moving at a much faster pace). I was reading the chapter on pointers and the -> (arrow) operator came up without explanation. I think that it is used to call members and functions (like the equivale...