Thread: Error...Help!![Warning] overflow in implicit constant conversion [-Woverflow]

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    17

    Error...Help!![Warning] overflow in implicit constant conversion [-Woverflow]

    while(fread(&stu, sizeof(stu),1,fp) == 1){
    if(strcmp(s_id, stu.ID) == 0){
    fflush(stdin);
    gotoxy(print,12);printf("ID: ");gets(stu.ID);
    gotoxy(print,13);printf("Name: ");gets(stu.name);
    gotoxy(print,14);printf("Address: ");gets(stu.add);
    gotoxy(print,15);printf("Parent's name: ");gets(stu.parname);
    gotoxy(print,16);printf("Class: ");scanf("%d",&stu.Class);
    gotoxy(print,17);printf("Phone Number: ");scanf("%ld",&stu.phone_no);
    fseek(fp,-sizeof(stu), SEEK_CUR);
    fwrite(&stu,sizeof(stu), 1, fp);
    isFound = 1;
    break;



    how to eliminate the error?
    fseek(fp,-sizeof(stu), SEEK_CUR);
    help...!

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    sizeof returns size_t. You can cast it to long if you want to mute the warning.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Sep 2015
    Posts
    17
    Thank you. could you write the coding? i don't get what you mean excatly

  4. #4
    Registered User
    Join Date
    Sep 2015
    Posts
    17
    I am a beginner in c...and i need this for my homework..thanks a lot for your help.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Especially since it's for homework, nobody here will write the code for you. Also, it appears you're using Turbo C++. We recommend a newer compiler/IDE, like Visual Studio, Eclipse, or Code::Blocks.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by Carlies View Post
    while(fread(&stu, sizeof(stu),1,fp) == 1){
    if(strcmp(s_id, stu.ID) == 0){
    fflush(stdin);
    gotoxy(print,12);printf("ID: ");gets(stu.ID);
    gotoxy(print,13);printf("Name: ");gets(stu.name);
    gotoxy(print,14);printf("Address: ");gets(stu.add);
    gotoxy(print,15);printf("Parent's name: ");gets(stu.parname);
    gotoxy(print,16);printf("Class: ");scanf("%d",&stu.Class);
    gotoxy(print,17);printf("Phone Number: ");scanf("%ld",&stu.phone_no);
    fseek(fp,-sizeof(stu), SEEK_CUR);
    fwrite(&stu,sizeof(stu), 1, fp);
    isFound = 1;
    break;



    how to eliminate the error?
    fseek(fp,-sizeof(stu), SEEK_CUR);
    help...!
    You have several problems with the code presented:

    1) You do not present the entire program, only a section of the code. It is impossible for us to attempt to compile your code to find the errors.

    2) You appear to be using conio. conio is non standard and should be avoided. You could use a curses library which is available for Windows, Linux, and probably other O/Ss.

    3) You are using gets() which should NEVER be used, has been depreciated in the C99 C Standard, and has been eliminated in the C11 Standard. fgets() should be used instead.

    4) flush(stdin), again, should NEVER be used! The following is the better alternative:
    Code:
    int ch;
    while ((ch = getchar()) != '\n' && ch != EOF);
    5) sizeof(), strlen(), and others return a size_t value, an unsigned integer type, implementation defined.

    Start with resolving these problems

  7. #7
    Registered User
    Join Date
    Sep 2015
    Posts
    17
    Okay,thank you for giving me such helpful advice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 07-24-2011, 11:34 PM
  2. warning: deprecated conversion from string constant to char*
    By Albinoswordfish in forum C++ Programming
    Replies: 2
    Last Post: 12-23-2008, 10:24 AM
  3. Replies: 7
    Last Post: 09-24-2008, 03:48 AM
  4. integral constant overflow error?
    By paperbox005 in forum C Programming
    Replies: 3
    Last Post: 05-06-2005, 09:44 PM
  5. Error: Implicit conversion from void*
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 12-12-2001, 02:38 PM