0

he below code works fine with dec c++ compiler but when run on visual studio gives the error at fseek

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
int main()
{
     FILE *fp;
     char *stringBuff;
     int i;
     int epi = 0;
     long lSize;
    fopen_s (&fp, "sequence.txt" , "rb" );
     fseek (fp ,0 , SEEK_SET);
     lSize = ftell (fp);
     rewind (fp);
     stringBuff = (char*) malloc (sizeof(char)*lSize);
     fread (stringBuff,1,lSize,fp);
     for(i = 0 ; i < lSize; i++)
     epi = epi + 2 * (stringBuff[i] - 48 ) - 1;
     
     printf("%d", epi);
     getch();
     return ;
     
}
     
     

//error Native' has exited with code 3 (0x3).
2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Salem
0

What error (we can't see your screen)?

Perhaps if you added some error checking code, rather than blindly assuming that success is guaranteed, you might be able to ask a more direct question.

0

What error (we can't see your screen)?

Perhaps if you added some error checking code, rather than blindly assuming that success is guaranteed, you might be able to ask a more direct question.

I am sorry that i didn't tell what was the exact problem. The code i have put on the thread works fine with dav c++ compiler but when the same code is run with visual c++ it gives error with fseek saying its assertion problem please read the document of the visual studio and it crashes

0

Understand that failure to crash on one system is not a proof of correctness. More often than not, it just makes you lucky (not good).

The real proof comes when you start running the code through many different compilers, on many different operating systems.

Since you don't actually (still!) post any error messages, I'm going to hazard a guess that your assert says something like stream != NULL.

In which case, you FAILED to open the file, and you FAILED to check the return status.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.