Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

new to gcc and this stuff...

hi there,

I'm completely new to c on a linux system (it's a SuSE distribution), I have founded out how to compile and link my program using the build in gcc tool.

But now I stand in front of a big problem, I started programming in c with c++ - I wanted to use the "new" operator, but - as you can guess, it did not work.

I have tried to include some header files I well know, so I tried to include "conio.h" to have e.g. the "gotoxy" command, to simple print something on screen to make me happy again, but there isn't a conio.h header file the compiler says.

Where can I find a overview over all theese header Files in /usr/include? Or, where can I find commands to give out something on screen on the position I want to?
best regards,

sebastian mohrenstecher
executive secretary
net::allies

www.net-allies.de
info@net-allies.de

Comments

  • XfactorXfactor Member Posts: 343
    : hi there,
    :
    : I'm completely new to c on a linux system (it's a SuSE distribution), I have founded out how to compile and link my program using the build in gcc tool.
    :
    : But now I stand in front of a big problem, I started programming in c with c++ - I wanted to use the "new" operator, but - as you can guess, it did not work.
    :
    : I have tried to include some header files I well know, so I tried to include "conio.h" to have e.g. the "gotoxy" command, to simple print something on screen to make me happy again, but there isn't a conio.h header file the compiler says.
    :
    : Where can I find a overview over all theese header Files in /usr/include? Or, where can I find commands to give out something on screen on the position I want to?
    : best regards,
    :
    : sebastian mohrenstecher
    : executive secretary
    : net::allies
    :
    : www.net-allies.de
    : info@net-allies.de

    C++ isn't compatible in C. But C is compatible in C++. So since the new operator is a C++ op, then it isn't compatible. You probable should get a book on C.
    X
  • SouldrinkerSouldrinker Member Posts: 143
    [b][red]This message was edited by Souldrinker at 2002-9-20 0:21:37[/red][/b][hr]
    yeah - have got one and readed it, it's that "alloc" thing I have remembered dark in my brain ;)

    But one problem still is there (after allocating a bit and using ncurses.h to draw those nice things on screen every GUI needs), I allocate memory using calloc to create a string in memory, this is my code:

    [code]
    char *user_name = calloc (10 1);
    [/code]

    I remembered the basics on c and c++ and all other languages, and so I know that a char has 1 byte I need to allocate in memory, now my compiler gives me the following warning-message, and I don't know why:

    [code]
    test.c:48: warning: initialization makes pointer from integer without a cast
    [/code]

    But I do not make a pointer from integer, I want to allocate memory for a char-array (which is a string), the code works - I can save 10 Chars in the string, but I hate those warning-messages when I compile my source-code.

    Would be glad if anyone knows how to get this messages away (without turning off warnings in my compiler :D)

    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    info@net-allies.de



  • XfactorXfactor Member Posts: 343
    [b][red]This message was edited by Xfactor at 2002-9-20 3:2:10[/red][/b][hr]
    : [b][red]This message was edited by Souldrinker at 2002-9-20 0:21:37[/red][/b][hr]
    : yeah - have got one and readed it, it's that "alloc" thing I have remembered dark in my brain ;)
    :
    : But one problem still is there (after allocating a bit and using ncurses.h to draw those nice things on screen every GUI needs), I allocate memory using calloc to create a string in memory, this is my code:
    :
    : [code]
    : char *user_name = calloc (10 1);
    : [/code]
    :
    : I remembered the basics on c and c++ and all other languages, and so I know that a char has 1 byte I need to allocate in memory, now my compiler gives me the following warning-message, and I don't know why:
    :
    : [code]
    : test.c:48: warning: initialization makes pointer from integer without a cast
    : [/code]
    :
    : But I do not make a pointer from integer, I want to allocate memory for a char-array (which is a string), the code works - I can save 10 Chars in the string, but I hate those warning-messages when I compile my source-code.
    :
    : Would be glad if anyone knows how to get this messages away (without turning off warnings in my compiler :D)
    :
    : best regards,
    :
    : sebastian mohrenstecher
    : executive secretary
    : net::allies
    :
    : www.net-allies.de
    : info@net-allies.de

    Well, I've gotten that error thousands of times but I need to look at your code to know which variable is a conflicting type. Somewhere you have a type that doesn't match the function or cast. You don't have to post all of it if it's kind of lengthy, but just post where you know the problem is. Also make sure you post your declarations of the variables in that specific function.
    Also, I would use malloc instead of calloc. I've been told why you should use malloc instead of calloc but I don't remember. If anyone knows please post it.
    X


  • DB1DB1 Member Posts: 1,142
    : : yeah - have got one and readed it, it's that "alloc" thing I have remembered dark in my brain ;)
    : :
    : : But one problem still is there (after allocating a bit and using ncurses.h to draw those nice things on screen every GUI needs), I allocate memory using calloc to create a string in memory, this is my code:
    : :
    : : [code]
    : : char *user_name = calloc (10 1);
    : : [/code]
    : :
    : : I remembered the basics on c and c++ and all other languages, and so I know that a char has 1 byte I need to allocate in memory, now my compiler gives me the following warning-message, and I don't know why:
    : :
    : : [code]
    : : test.c:48: warning: initialization makes pointer from integer without a cast
    : : [/code]
    : :
    : : But I do not make a pointer from integer, I want to allocate memory for a char-array (which is a string), the code works - I can save 10 Chars in the string, but I hate those warning-messages when I compile my source-code.
    : :
    : : Would be glad if anyone knows how to get this messages away (without turning off warnings in my compiler :D)
    : :
    : : best regards,
    : :
    : : sebastian mohrenstecher
    : : executive secretary
    : : net::allies
    : :
    : : www.net-allies.de
    : : info@net-allies.de
    :

    Just let the compiler automatically allocate memory for you.
    [code]
    char *user_name;
    or
    char user_name[10];
    [/code]

  • ignatandrignatandr Member Posts: 10
    : [b][red]This message was edited by Xfactor at 2002-9-20 3:2:10[/red][/b][hr]
    : : [b][red]This message was edited by Souldrinker at 2002-9-20 0:21:37[/red][/b][hr]
    : : yeah - have got one and readed it, it's that "alloc" thing I have remembered dark in my brain ;)
    : :
    : : But one problem still is there (after allocating a bit and using ncurses.h to draw those nice things on screen every GUI needs), I allocate memory using calloc to create a string in memory, this is my code:
    : :
    : : [code]
    : : char *user_name = calloc (10 1);
    : : [/code]
    : :
    : : I remembered the basics on c and c++ and all other languages, and so I know that a char has 1 byte I need to allocate in memory, now my compiler gives me the following warning-message, and I don't know why:
    : :
    : : [code]
    : : test.c:48: warning: initialization makes pointer from integer without a cast
    : : [/code]
    : :
    : : But I do not make a pointer from integer, I want to allocate memory for a char-array (which is a string), the code works - I can save 10 Chars in the string, but I hate those warning-messages when I compile my source-code.
    : :
    : : Would be glad if anyone knows how to get this messages away (without turning off warnings in my compiler :D)
    : :
    : : best regards,
    : :
    : : sebastian mohrenstecher
    : : executive secretary
    : : net::allies
    : :
    : : www.net-allies.de
    : : info@net-allies.de
    :
    : Well, I've gotten that error thousands of times but I need to look at your code to know which variable is a conflicting type. Somewhere you have a type that doesn't match the function or cast. You don't have to post all of it if it's kind of lengthy, but just post where you know the problem is. Also make sure you post your declarations of the variables in that specific function.
    : Also, I would use malloc instead of calloc. I've been told why you should use malloc instead of calloc but I don't remember. If anyone knows please post it.
    : X
    :

    I think the problem is that you just forgot to [size=3][red]include [/red][/size] file. Without it the compiler gives you a warning because it can not check the function prototype, and assumes the malloc returnes integer (by default).
    The main difference between malloc and calloc is that the memmory allocated by calloc() is always initialized to 0. There is no such guarantee that malloc() will initialize the memory.
    Try this code:
    :[code]
    /* Use the calloc() function */
    #include
    #include

    int main(void)
    {
    float *ptr1, *ptr2;
    int i, n;

    n = 5;
    ptr1 = malloc(n * sizeof(float));
    ptr2 = calloc(n, sizeof(float));

    if (ptr1 == NULL)
    printf("malloc() failed.
    ");
    else if (ptr2 == NULL)
    printf("calloc() failed.
    ");
    else{
    for (i=0; i<n; i++)
    printf("ptr1[%d]=%5.2f, ptr2[%d]=%5.2f
    ",
    i, *(ptr1 + i), i, *(ptr2 + i));
    free(ptr1);
    free(ptr2);
    }
    return 0;
    }
    :[/code]
    Regards, ignatandr.
    :

  • SouldrinkerSouldrinker Member Posts: 143
    this worked... thank you very much

    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    info@net-allies.de

  • mirage_guymirage_guy Member Posts: 5
    : this worked... thank you very much
    :
    : best regards,
    :
    : sebastian mohrenstecher
    : executive secretary
    : net::allies
    :
    : www.net-allies.de
    : info@net-allies.de
    :
    :



    Y isnt there the CONIO.H file in gcc ?? can anyone pls help me out?!!

  • Andre YoungAndre Young USAMember Posts: 0

    __ // http://forcoder.org // free video tutorials and ebooks about || R, Visual Basic, Perl, Delphi, Python, PL/SQL, Assembly, PHP, C++, JavaScript, Ruby, MATLAB, Java, Visual Basic .NET, Go, C#, Scratch, Swift, C, Objective-C Scheme, Erlang, Awk, LabVIEW, Alice, ML, Transact-SQL, F#, Kotlin, Rust, SAS, D, Lua, VBScript, Bash, Julia, Apex, Prolog, Dart, FoxPro, Ada, Scala, COBOL, Crystal, Hack, Fortran, Lisp, ABAP, Clojure, Logo || _______

Sign In or Register to comment.