3 Replies - 445 Views - Last Post: 18 December 2012 - 04:07 PM Rate Topic: -----

#1 Snow1986   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 01-September 12

Problem with a print statement

Posted 18 December 2012 - 03:37 PM

I am brand new to C I have a background in Java but I am reading through a book that introduces me to Objective-C but it begins with C first. I am trying to play with functions and I am having a difficult time trying to get a print statement to work. my code is:
#include <stdio.h>
void congratulateStudent(char student, char course, int numDays)
{
    printf("%s has done as much %s Programming as I could fit into %d days.\n", student, course, numDays);//my error is Format specifies 'char*' but the argument has type 'char'

}

int main (int argc, const char * argv[])
{
    congratulateStudent("Mark", "Cocoa", 5);
    return 0;
}




How do I resolve this?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with a print statement

#2 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: Problem with a print statement

Posted 18 December 2012 - 03:53 PM

What is the problem with your code? Does it compile without warnings or errors?

Post your error messages, exactly as they appear in your development environment.

Also you may want to study this link: Variables and Character sequences. And also the documentation of printf()

Jim

This post has been edited by jimblumberg: 18 December 2012 - 03:55 PM

Was This Post Helpful? 0
  • +
  • -

#3 Snow1986   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 01-September 12

Re: Problem with a print statement

Posted 18 December 2012 - 03:59 PM

I put a notation next to where my error appears hence the// but I guess I should have explained in more detail what was occurring. My issue is with the %s and the %d and the corresponding variable names also I am getting an issue with the char(what I would call strings in Java) from the main for whatever reason they are not being passed to the other function. Thank you.
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1695
  • View blog
  • Posts: 8,592
  • Joined: 07-September 06

Re: Problem with a print statement

Posted 18 December 2012 - 04:07 PM

The problem is that in C/C++ char is a single character such as 'a', not a string. You are attempting to pass a string to your function:

congratulateStudent("Mark", "Cocoa", 5);


But your function only takes characters, not strings:
void congratulateStudent(char student, char course, int numDays)


If you want to send a string you need to use the char* datatype (for multiple characters stored in a single area - as an array, but I believe that is likely beyond your current understanding -- I am not trying to be mean here, just pointing out the differences in datatypes), not the char datatype.

Hopefully that helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1