program compile help

This is a discussion on program compile help within the C Programming forums, part of the General Programming Boards category; Hi all.. I'm trying to use someone else's design for a project i'm working on but have to compile some ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    program compile help

    Hi all..

    I'm trying to use someone else's design for a project i'm working on but have to compile some code that is pretty short but will not compile.

    it is a program to load a video data stream file to memory and then send it to the parallel port uninterrupted using a pc in dos, data flow is controlled by the ACK input on the parallel port from an external CPLD.

    here is the code...

    Code:
    /*********************************************
    
       READ_PSK.C   
    
       READING  SOFTWARE FOR .PSK  FILES
    
       May 16th 2004
    
       (C) 2004  J.F. FOURCADIER  F4DAY
    
    *************************************************/
    
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    #include <stdlib.h>
    
    int main (void)
    {
           char nomfich[51];
           FILE *data_file;
           int base = 0x78C0; // output port address
           int data_reg = base + 0;
           int status_reg = base + 1;
           unsigned char *buf;
           unsigned long n;
           int k = 0;	
           // FILE SIZE
           // DATV_0 =  283968L
           // DATV_1 = 7497408L
           // DATV_3 = 1060800L
           long filesize = 7497408L; // file size
           buf = malloc(filesize);
           clrscr();
    
           data_file = fopen("C:\\DJGPP\\MYPRO\\datv_1.psk","rb");
           if (data_file == 0)
                {
                    printf("fopen failed\n");
                    printf("\n\nname of file should be datv_x.psk  !\n");
                    exit(1);
                }
           else
           {
           printf("\nreading.....");
           }
           fread(buf,1,filesize,data_file);
           fclose(data_file);
    
           disable();
           printf("\ntransmitting.....");
           n = 0;
           do
           {
           do
               {
               outportb(data_reg,*(buf+n));
               // wait for next state on nAck :
               do { } while (((inportb(status_reg)) | 0xBF) != 0xFF);
               n++;
               outportb(data_reg,*(buf+n));
               // wait for next state on nAck :
               do { } while (((inportb(status_reg)) | 0xBF) == 0xFF);
               n++;
               }
           while(n <= (filesize - 1));
           n=0;
           k++;
           }
           while(!0);	// endless loop
    //     while(k<500);
    
           free(buf);
           enable();
           
           exit(0);
    }
    So the problem is when i try to compile i get this error for this line:
    >>>>buf = malloc(filesize)

    Error: Invalid conversion from 'void*' to 'unsigned char*'

    Compiler i'm using is DJGPP with c and c++ parts installed.


    i havent a clue really about pointers etc so i'm not sure what is wrong.....
    can anyone help?

    thanks

    Rob

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Do you seriously have anything against writing modern programs? Port this over to something realistic.

    Anyway, your actual problem here is possibly that you have to cast malloc() on this ancient compiler.

    Code:
    buf = (unsigned char *)malloc(filesize);

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    The design i'm buiding from is not my own and i can only just about do the basics in C so this will have to do for now, it is supposed to rely on dos to be able to work fast enough aparrently, but what do i know...ha

    will give your idea a try..

    thanks

    Rob

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    If it requires casting, then it must be compiled as C++, since C doesn't require casting... So, this is supposed to be done in C? Then why is the library compiled as C++?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    > Error: Invalid conversion from 'void*' to 'unsigned char*'
    This usually means you're compiling your C program with a C++ compiler.
    Try
    gcc prog.c
    rather than
    gxx prog.cpp

    And what does "uninterrupted" mean?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    Quote Originally Posted by Salem View Post
    > Error: Invalid conversion from 'void*' to 'unsigned char*'
    This usually means you're compiling your C program with a C++ compiler.
    Try
    gcc prog.c
    rather than
    gxx prog.cpp

    And what does "uninterrupted" mean?

    As far as i can tell it disables all other activities like keyboard input etc to reduce any chance of data flow 'glitches'.
    I think the loading to memory is meant to reduce the chance for delays compared with sending the file direct from the disk.

    Anyway i did add the casting as above and it coompiled first time.. now to test!

    Like i said i haven't much idea about programming.
    This is a relatively small part of the project (a digital television transmitter for ham radio), the hardware was the main task so i don't want to spend much time here until it can actually get the whole thing working in a fashion!

    Rob

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Compile Public Domain Pocket PC C Program
    By m1l in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 07-20-2007, 04:02 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. new to C--can't get program to compile
    By samerune in forum C Programming
    Replies: 12
    Last Post: 04-02-2007, 09:44 AM
  5. how do i compile a program that deals w/classes?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2001, 01:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21