rendered paste body*
* File: cuExams.c
* Author: vikky
*
* Created on October 26, 2006, 6:14 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
struct MemoryStruct {
char *memory;
size_t size;
};
void *myrealloc(void *ptr, size_t size) {
/* There might be a realloc() out there that doesn't like reallocing
NULL pointers, so we take care of it here */
if(ptr)
return realloc(ptr, size);
else
return malloc(size);
}
size_t
WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) {
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)data;
mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
if (mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}
return realsize;
}
char *before(char *str1, char *str2){
char *newstr = NULL;
int offset = 0;
if ((newstr = strstr(str1, str2)) != NULL) {
offset = newstr - str1;
newstr = (char*)malloc(offset + 1);
strncpy(newstr, str1, offset-1);
newstr[offset] = 0;
return(newstr);
}
else
return(NULL);
}
/*
*
*/
int
main(int argc, char** argv) {
CURL *curl_handle;
struct MemoryStruct chunk;
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
chunk.size = 0; /* no data at this point */