Howdy, Stranger!

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

Categories

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:
[code]
[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("
STUDENT RECORD SYSTEM

");
[9]: /*Acquiring student data*/
[10]: for (row = 0; row <= 4; row++)
[11]: {
[12]: printf("
STUDENT NO: ");
[13]: gets(studno[col][row]);
[14]: }
[15]:
[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]: }
[/code]
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.

Comments

  • DariusDarius Member Posts: 1,666
    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

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

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

Sign In or Register to comment.