LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 11-04-2007, 09:11 PM   #1
YolLuTRaC
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Rep: Reputation: 0
Quotation mark in fprinf problem...


This is my code and apparently it won't take the quotation marks even if I put a \ in front of it!

Code:
#include <stdio.h>
#include <string.h>

int main(){

	FILE* file;
	FILE* output;
	int i = 0;
	char string[500];
	
	if(((file = fopen("try.txt", "r")) != NULL) && ((output = fopen("random.txt", "w")) != NULL)) {

		while(fgets(string, 499, file) != NULL) {
		
			string[(strlen(string) - 2)] = '\0';
			
			fprintf(output, "	histsArrayGood[h%s] = new TH1F( \"g_h%s\", \"Actual %s\", Nb_Blocks[%i], X_Min, X_Max);\n", string, string, i, string);
			fprintf(output, "	histsArrayGood[h%s] = new TH1F( \"g_h%s\", \"Actual %s\", Nb_Blocks[%i], X_Min, X_Max);\n", string, string, i, string);
			
			
			i++;
		
		}
		
	}
	
	fclose(file);
	fclose(output);
	
	return(0);

}
Here's the error message:

Code:
faster.c: In function 'main':
faster.c:17: warning: format '%s' expects type 'char *', but argument 5 has type 'int'
faster.c:17: warning: format '%i' expects type 'int', but argument 6 has type 'char *'
faster.c:18: warning: format '%s' expects type 'char *', but argument 5 has type 'int'
faster.c:18: warning: format '%i' expects type 'int', but argument 6 has type 'char *'
I'm running gcc 4.1.2 (Gentoo 4.1.2 p1.0.2)...

I'm just tired of trying to look around for the answer. Thanks for helping guys!
 
Old 11-04-2007, 09:33 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
i dont think it has anything to do with the quotation marks.

first, note these are warnings not errors, so the code should compile and run. but it is good that you want to prevent any warnings from occurring within your code.

the problem is with the parameters to the fprintf calls. when you use fprintf, you are specifying to print: %s, %s, %s, and then %i. but your parameters are string, string, int, string. switching the order of the last two should get rid of the errors.

Last edited by nadroj; 11-04-2007 at 09:34 PM.
 
Old 11-04-2007, 09:39 PM   #3
YolLuTRaC
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Well it would segfault when I was running it. Anyway yes I must be very sleepy since it is a pretty obvious mistake. Thanks by the way. It's solved...
 
  


Reply



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
Execvp With Quotation Marks amitbern Programming 10 11-25-2005 10:28 AM
no quotation marks jdoe9898 Linux - Newbie 1 10-12-2005 03:07 AM
an anti-Windows quotation joshknape General 2 08-02-2005 09:44 PM
Emacs's mark set key(ctrl+space) problem. ayiiq180 Linux - Software 1 06-15-2005 10:45 AM
typing a quotation mark in text editors cyberhawk Linux - General 2 04-16-2004 07:51 PM

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

All times are GMT -5. The time now is 07:45 PM.

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