c

How do I treat a pointer as a multi array?

Hi, I have this loop which gives seg. fault. s->c = malloc(width * height * sizeof(double)); if (s->c == NULL) { puts("malloc failed"); exit(1); } for (int n = 0; n < width; n++) { for (int m = 0; m < height; m++) { d = (&s->c)[m][n]; printf("d %f\n", d); printf("m %i\n", m); printf("n %i\n", n); ...

Parse html page source with libcurl and C

How can I print the source of a webpage, specified in curl_easy_setopt, without html tags? So, printing only the text in the source? ...

iconv encoding conversion problem

I am having trouble converting strings from utf8 to gb2312. My convert function is below void convert(const char *from_charset,const char *to_charset, char *inptr, char *outptr) { size_t inleft = strlen(inptr); size_t outleft = inleft; iconv_t cd; /* conversion descriptor */ if ((cd = iconv_open(to_charset, from_ch...

Curly braces without variable declaration

Why sometimes C code gets wrapped with curly braces without declaring a variable in them? e.g. (from FreeRTOS source code, file 'tasks.c'): portENTER_CRITICAL(); { xTicks = xTickCount; } portEXIT_CRITICAL(); ...

Is there a C/C++ project similar to portablepython?

I've searched the internet for this but couldn't find anything useable, I was just wondering if there exists a C/C++ project similar to portablepython? EDIT I guess the question becomes: is there a portable C/C++ compiler I can stick onto a usb key? ...

How to print in C

Very much a beginner to c, in fact this is my first tester programme cant actually figure out how to print this number out to the terminal #include <stdio.h> int addNumbers(int a, int b) { int sum = a + b; return sum; } int main(void) { int a = 4; int b = 7; printf(addNumbers(a,b)); return 0; } im sure tha...

can someone help me translate this c++ code to c?

this is a magic square generator, but do not know C++, I have some difficulties to convert this code: #include <vector> #include <iostream> using namespace std; //There two series will be on even in case of magic square // One of even order will be for multiple of 4 void BuildDoublyEvenMagicSquare(vector<vector<int> > &mat, int Order); ...

Getting a hexadecimal number into a program via the command line

I can do this: int main(int argc, char** argv) { unsigned char cTest = 0xff; return 0; } But what's the right way to get a hexadecimal number into the program via the command line? unsigned char cTest = argv[1]; doesn't do the trick. That produces a initialization makes integer from pointer without a cast warning. ...

Server multi-threading, a must for Protocol ? and more

Suppose a application level protocol is implemented via UDP. Client timeout is required, thus server need to keep state of each client it talks to. Also suppose select is used. Is it always the best to implement multi-threading server? I figure a link-list will do the same, where server timeout time=Earliest Timeout of a client- Curre...

Pointers, Arrays, printf

I'm trying to use an array to hold inputs for a survey that will have equal positive values on each side, but have a pointer point to the center of the array so negative pointer values can be used to access the array. For example, the array would hold values from 0 to 30, the pointer would point to 15, and the user would be prompted t...

Unix makefile error: 'make: Fatal error: Don't know how to make target '

I have the simplest of makefiles: threads: gcc threads.c -o threads but I get the error: 'make: Fatal error: Don't know how to make target' Any ideas what I am doing wrong? It's probably something simple - I made the makefile in emacs on the system which is trying to run it (Unix) ...

Installing C/C++ libraries on Windows

I'm studying (well, trying to) C right now, but I'm limited to working in Windows XP. I've managed to set up and learn how to use Emacs and can compile simple C programs with gcc (from Emacs no less!), but I'm getting to the point where I'd like to install something like SDL to play around with it. The thing is that the installation in...

How can I initialize a static pointer in C?

I want to use a static pointer in a function in order to point to a number of integers. The number of integers is not yet known while programming but it is known on runtime before the function is used first. So I want to give the function a parameter n and tell it to allocate memory space for n integers to the pointer and keep this. Howe...

A scripting language to simply compile

I'm looking for a simple script language which I can compile easily by just putting the .h files under an include folder and the .c/.cpp files under a source directory. Something without any Makefile. Must be written in C/C++ rather C++. ...

C: Missing some logic with the pointers stuff...

I am writing my own string copy function. The following works: char *src, *dest; src = (char *) malloc(BUFFSIZE); //Do something to fill the src dest = (char *) malloc(strlen(src) + 1); mystringcpy(src, dest); void mystringcopy(char *src, char *dest) { for(; (*dest = *src) != '\0'; ++src, +dest); } But this doesn't work: char *sr...

Access violation writing location 0x00000000. reading int from keyboard

I am trying to read the input from a keyboard which i will use to create a set of multiplications. If i hardcode the integer to use then the program works fine however when i let the user enter their own number the program crashes and shows an error about an access violation. I'm sure this is something simple but as I am fairly new to C...

Send a file to a socket

Hello. I'm trying to send a file to a particular socket using C; here's the code: int send_file(char *filepath,int sock) { FILE *fp=fopen(filepath,"rb"); void *buff=malloc(2000); int i=1; while(i) { int bytes_read=fread(buff,1,2000,fp); i=!(feof(fp)); int bytes_sent=0; while(bytes_sent...

Eclipse: Create Hello World app in C

This seems super basic, but I'm having trouble finding documentation online to explain it. I have the Eclipse IDE for C/C++ 3.5.1. How can I create a simple Hello World program in C? (I have also downloaded cygwin.) Many tutorials online make reference to "Managed" and "Simple" types of projects, but I can't find that anywhere. Was that...

Initializing nested structures without defining all fields

I have a set of structs, defined as follows: typedef struct { int index; int array[10]; } Item; typedef struct { Item A; Item B; Item C; } Collection; And I want to declare a variable of type Collection as follows: Collection collection = { { 1, 0 }, /* item A */ { 2, 0 }, /* item B */ { 3, 0 } /*...

help on win32 api in assembly

why are the structure declarations in assembly different from those in the win32 api documentation.(i am coming from c++ and trying my hand at assembly language) for example i got this function prototype from icezelion's tutorials(tutorial3) WNDCLASSEX STRUCT DWORD cbSize DWORD ? style DWORD ? ...