What is a none portable pointer?

I'm current working on a program about 2D Arrays currently with string. I wanted to store the data using a loop but I keep on receiving this kind of warning message:
:-( [b][red]Warning test14.c 13: Non-portable pointer conversion in function main[/red][/b] :-(
And the program also hangsup the O.S.
I'm currently new to record-type programming in C. This is the code by the way:
[1]: #include
[2]: /*Using 2D Arrays of String*/
[3]: main(void)
[4]: {
[5]: char studno[10][4], studfname[10][4], studlname[10][4], studmi[5][4];
[6]: int row, col;
[7]: row = 0; col = 0;
[8]: printf("

[9]: /*Acquiring student data*/
[10]: for (row = 0; row <= 4; row++)
[11]: {
[12]: printf("
[13]: gets(studno[col][row]);
[14]: }
[16]: row = 0; col = 0;
[17]: /*for printing data from the array*/
[18]: for (row = 0; row <= 4; row++)
[19]: {
[20]: printf("
STUDENT NO: %s", studno[col][row]);
[21]: }
[22]: }
Anyone can help me figure this out. I have to say arrays are a little bit confusing. Im using Borland Turbo C Version 2.0. I didn't use scanf coz its have a problem accept data of string with space.


  • It's not 'non portable pointer' it's 'non portable pointer CONVERSION'. Pointers themselves are obviously portable, they are part of the language.

    Anyways, the compiler is converting a char to a pointer.

    The problem is gets() expects a pointer and you are giving it a character. If you want to read a character then use getchar() if you want to read a string then you need to pass a character pointer. I've already erased your code and I don't feel like finding out what would be the most likely code that you MEANT to write, so you'll need to figure it out on your own.

    On a side note (and especially for this), you shouldn't use gets(). gets() is not safe from a security and a robustness sense. The problem is gets() doesn't know the size of the buffer you provide for it and so can write past the end of the buffer destroying memory and typically resulting in the program crashing. This can sometimes be used creatively to execute arbitrary code. If the program was running at a higher privelege level, then you could get code to execute at that higher privelege level that shouldn't be executing. You should instead use fgets() specifying stdin as the file. fgets() takes three parameters, the file, the size in bytes to read, and a buffer to hold the data. The buffer would be the same thing you would pass to gets() the file would be stdin to get data from the keyboard and the size would be the size of the buffer (i.e. the maximum number of characters to read).

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

Sign In or Register to comment.

Howdy, Stranger!

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


In this Discussion