I am trying to write a program that will read the existing records of a file and then index them in another file. The records are stored in the file named "players.bin" which is CSV format each record contains (username,lastname,firstname,numwins,numlosses,numties and i want to index them in a new file named "players.idx". However the ...
How can I split up a string into pieces? For example, how can I place "orld." into a variable called one, "Hello" into a variable called three, and " w" into two?
#include <string.h>
#include <stdio.h>
int main(void)
{
char *text ="Hello World."; /*12 C*/
char one[5];
char two[5];
char three[2];
return 1;
}
...
Hi !
Have a problem with fscanf() - it does not skip to the next word after reading 10 characters from the file
while(fscanf(TEXT_FILE,"%10s", str) != EOF) // reads up to 10 char into str
If it find the word that is greater than 10 characters, it will read 10 characters, store them into str, continue in the same word reading up to...
After reading a series of man pages and searching through google, I decided to post this question to the bright folks of stack overflow.
I'm working on a basic Unix Shell and one of the requirements is that I have to implement a command to echo out the shell's pid in base 10 ASCII... Before I read this requirement, I had assumed that pr...
/* DATABASE INIT */
ret = sqlite3_open_v2(dbfile, &DB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (SQLITE_OK != ret) {
printf("Could not open database.\n");
exit(1);
}
const char* zSql = "INSERT INTO abc VALUES (?)";
ret = sqlite3_prepare_v2(sites[DB, zSql, strlen(zSql), &s, NULL);
if (SQLITE_OK != ret) {
pri...
Hi,
I am using C programming language in Linux platform and my question is how can I know how much I allocated in heap memory and other useful information such as peak usage in the heap memory. Is there a standard C function for this implementation?
Please advice.
Many thanks.
...
I have a binary file in CSV format that contains multiple records. Each record is entered in as user_name, last_name, first_name, num_wins, num_losses, num_ties. I am creating a method to update a certain players record of wins,losses and ties. The user inputs the username to change followed by the changes to the wins, losses and ties. ...
Hello,
gcc 4.4.5 c89
I recently downloaded and installed log4c on my development machine.
I put all the headers and includes in the following directories.
project_name/tools/log4c/inc
project_name/tools/log4c/libs
However, as I installed the headers where in the system path:
/usr/include/log4c/*.h
So in my project, when I was i...
Hi,
I've come across some code that has a large static function in a header file and i'm just curious when it is/is not ok to do this. For example, if many .c files include the header, why not just define the function non-static and link it in ?
Any advice or rules of thumb on when/when not to put static function definitions in header ...
Is the address returned by malloc a virtual address or is it the actual physical address where the memory is allocated?
Edit:
I read somewhere "In some implementations, calling free() releases the memory back to the system and in others it is released back to the process". Does "releasing back to the system" imply that the memory is th...
I have a piece of code that attempts to acquire the credentials for a user on a remote computer which I cant get working. currently this produces an access violation error (0xc0000005) when run:
SEC_WINNT_AUTH_IDENTITY_W identity;
ZeroMemory(
identity.Domain = (unsigned short *)_T("DOMAIN");
identity.DomainLength = lstrlenW(_T("DOMAIN...
I am trying to do merge sort using void*. If I keep numbers I want to sort to 1-byte it works perfectly. However if the number is located in more than 1 byte it doesn't work well. I believe it takes it as 2 numbers. I tested it with number 500 and at the end I have 256 and 244 not sorted ....
#include "msort.h"
#include <iostream>
usi...
Hi,
This post is edited and the original post here is asking the implementation of _malloc_r which is not a good move to use.
My question now is there any other malloc implementation or alternative function for malloc and free functions?
Please advice.
Many thanks.
...
I would like to use binary flags to represent a mathematical set in C, where "Bit i is set" means "item i is in the Set". This is convenient because operations like "union" and "intersection" are trivial to implement ("|" and "&"). However, I want my set to be able to contain more than 32 items. Furthermore, I want my code to work on bot...
Hi at all, there is someone that know if exist a XSD code generator for C source code?
I have a lot of xsd files and I need to generate C struct and relative function fromXml and toXml.
Thanks.
...
What are the different ways of ensuring that a bunch of pthreads all start at the same time?
I could find only one way, ie. initializing a barrier in the main thread, then waiting on it in the newly created pthreads.
...
For an embedded application, I am trying to implement a first-in, first-out (FIFO) queue of structs using ANSI C. The most straightforward way to do this seems to be by implementing a linked-list, so that each structure contains a pointer to the next in the queue. Hence I define the struct itself as:
typedef enum { LED_on, LED_off, etc ...
The size of an integer type (or any type) in units of char/bytes is easily computed as sizeof(type). A common idiom is to multiply by CHAR_BIT to find the number of bits occupied by the type, but on implementations with padding bits, this will not be equal to the width in value bits. Worse yet, code like:
x>>CHAR_BIT*sizeof(type)-1
ma...
I have multiple threads, and I want each thread to wait for every others to complete at certain point in the code before proceeding as following:
void *run() {
for (i=0;i<1000;i++){
do_1st();
// sync() all stop here wait for all then resume
do_2nd();
}
}
I tried to use pthread_cond_wait.. but It seems very complicated...
Hi,
I'm trying to make my first simple program that uses databases. I decided to use SQLite as it allows to store database into a single file. I think I have managed to do a database with SQLite Database Browser, but I have no idea how I could read that data in a C/C++ program. So can someone help me to get started or point me some tuto...