LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2006, 12:42 AM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
Question about this line "Couldn't load %s: %s\n" what does %s stand for?


Just a quick question about the following piece of code...

Code:
fprintf(stderr, "Couldn't load %s: %s\n", file_name,
... what does the %s sign mean/do? Is this a way to include characters otherwise would of ended the line of characters? I have did some search into this, didn't come with much of anything other then questions regarding it (in other ways then the way this is question is asking). I tried to run the code by itself with the following...

Code:
fprintf(stderr, "Couldn't load %s: %s\n");
I got this output...

Code:
george@georgescomp1:~/cfiles$ g++ RandomPercentageSign.cpp -o RandomPercentageSign
george@georgescomp1:~/cfiles$ ./RandomPercentageSign
Couldn't load X,\uffff\uffff\uffff\uffff\u05b7: \uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffff\uffffE\uffff)\uffff1\uffff\uffff\uffff9\uffffs\uffff\u05cdv
george@georgescomp1:~/cfiles$
I know the full code outputs that it could not find a certain file and says so... here is that code I retrived the above from:

Code:
    /* Load the BMP file into a surface */
    image = SDL_LoadBMP(file_name);
    if (image == NULL) {
        fprintf(stderr, "Couldn't load %s: %s\n", file_name, 
SDL_GetError());
        return;
    }
... here is the output if I have a program of mine not have the needed bmp in the directory the program is running in...

Code:
george@georgescomp1:~/cfiles/George Lair/030506/032906/041506$ ./test031206
Couldn't load background.bmp: Couldn't open background.bmp
Couldn't load background.bmp: Couldn't open background.bmp
Couldn't load background.bmp: Couldn't open background.bmp
... NOTE: It just went on for 15 or so lines until I escaped
Couldn't load background.bmp: Couldn't open background.bmp
Couldn't load background.bmp: Couldn't open background.bmp
Couldn't load background.bmp: Couldn't open background.bmp
george@georgescomp1:~/cfiles/George Lair/030506/032906/041506$
... so exactly what does the %s do? I am assuming it copies/paste a certain piece of text, but that is just a guess from what I see above. Thanx in advance...

Last edited by RHLinuxGUY; 04-16-2006 at 12:44 AM.
 
Old 04-16-2006, 01:07 AM   #2
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
%s is a conversion specifier for strings. From your code, you would need two values since there are two string conversion specifiers e.g.
Code:
fprintf(stderr, "Couldn't load %s: %s\n", file_name, someval);
 
Old 04-16-2006, 02:26 AM   #3
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
So for each conversion specifier (broken down: (conversion) Changing or turning a state or condition (specifier) limit/mark), it outputs a value. How does it know what value to output? The one directly adjacent (in this case to the right of %s?) to the conversion specifier? Or is there something that might be somewhere in the code that loads that value into that specifier? If none of the previously stated, how does it know what to output?
 
Old 04-16-2006, 03:29 AM   #4
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
From the bit of C that I know, conversion is done in order of the values listed in your print statements. So using the example above, the first %s would be converted to the value of file_name and the second one to the value of someval. Other languages have ways to change the order of conversion, so I am sure its possible in C.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie question: whats the difference between "su root", "su" and "su -&quo mojarron Slackware 9 12-07-2009 04:08 PM
bash question: how to do "for a in b do..." on the command line Kropotkin Linux - Newbie 7 02-03-2006 08:27 AM
shell script question: removing a line according to a duplicate "field" mattie_linux Linux - Newbie 1 01-12-2006 03:57 PM
cdrecord command-line parentheses "(" ")" coolingtower Linux - Software 1 10-28-2005 11:49 AM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 01:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration