• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

What does this error mean?

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so im trying to run one of my functions in my program and im getting a error that I've attached below. Im not sure what it is saying or how to fix it. could someone help me?
This is the function code its referring to:

Screen-Shot-2020-07-11-at-12.37.48-AM.png
[Thumbnail for Screen-Shot-2020-07-11-at-12.37.48-AM.png]
 
Bartender
Posts: 15735
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error quite literally says what's wrong: as its first argument it expects a pointer to a file, but instead you have passed it an array of characters.

To read from a string, use sscanf.
 
Rancher
Posts: 508
15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear in mind that the last string, the URL, will include the \n added by fgets().
 
Saloon Keeper
Posts: 28392
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The error quite literally says what's wrong: as its first argument it expects a pointer to a file, but instead you have passed it an array of characters.

To read from a string, use sscanf.



scanf - read and parse data from stdin
fscanf - read and parse data from a file
sscanf - parse data from a string (buffer)

printf has similar relatives.
 
Hanna Roberts
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok. Thanks for the help.
 
Hanna Roberts
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait so you said sscanf is for a string but I’m trying to making it parse each line in a file. Would it still be sscanf that I use?
 
Tim Holloway
Saloon Keeper
Posts: 28392
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fscanf is what you use when you want a single function to both read in a line of text and process it.

sscanf is what you use when you have already read in the line in a separate operation. Or if you got the line from a database or some other source/constructor and want to process it.

And actually, "scanf()" is just shorthand for "fscanf( stdin, ... )"
 
Hanna Roberts
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok I think I get it now
 
Hanna Roberts
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you know what could cause the error Illegal instruction: 4 to print?
 
Stephan van Hulst
Bartender
Posts: 15735
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us the latest version of your code and the full error message?
 
Tim Holloway
Saloon Keeper
Posts: 28392
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like the C/C++ equivalent of a NullPointerException. The "4" is often a reference to memory location (address) 4, which would not be a valid memory reference on most hardware platforms - for application programs, anyway. As to why "4" instead of "0" - well there are reasons, but they don't matter. Any memory reference down in the bottom of RAM is likely a problem.
 
Hanna Roberts
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok thank you. I think I was able to fix the problem
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic