Hi
I'm a complete C newbie. I do have some experience in Java, though. Anyway, I've been working on a small project in C (mostly for leaning purposes), and it compiles, but when I run it I get an error message. I've been reading around online, but haven't found anything that works in fixing it. Here's the error message and the offending code:
Code:C:\c_programs\test2>up2.exe 7 [main] up2 1280 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIO LATION 831 [main] up2 1280 open_stackdumpfile: Dumping stack trace to up2.exe.stack dump 876694 [main] up2 1280 _cygtls::handle_exceptions: Exception: STATUS_ACCESS_VIO LATION 898744 [main] up2 1280 _cygtls::handle_exceptions: Error while dumping state (p robably corrupted stack)
Any help you can give me would be much appriciated. Thank you.Code://up2.c #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> struct Data{ int currentAmount; int isactive; }; struct Data* data; static char buffer[5000]; void updateCurrentAmount(void){ static char lookFor[] = "amount="; //this string immediatly preceads the amount char* startOfExpression = strstr(buffer, lookFor); if (startOfExpression == NULL){ //we have problems printf("ERROR - Error parsing charpane.php"); exit(-1); } char* startOfNumber = startOfExpression + strlen(lookFor); data->currentAmount = atoi(strncpy("", startOfNumber, 5)); } //tests updateCurrentLevel function int main(){ strcpy(buffer, "name=fred amount=12345 isactive=1"); data = (struct Data*) malloc(sizeof(struct Data)); updateCurrentAmount(); printf("current level = %i", data->currentAmount); return 0; }



LinkBack URL
About LinkBacks


