Week 12 Lecture.docx - Strings Input Output Strings are not an actual type in C but they are an array of characters If string no need for if single

Week 12 Lecture.docx - Strings Input Output Strings are not...

This preview shows page 1 out of 1 page.

Strings, Input, Output Strings are not an actual type in C, but they are an array of characters If string, no need for &, if single character, need &. If use %c for char name[31], will only print first char; need & If use %s for char name[31], will print everything stored. for (i=0;name[i]!=’\n’;i++){ printf(“%c”, name[i]); } printf(&arrayname) will print the first element of the array pointer holds the address of another variable char * name and char name[] are the same!! When printing something you are passing, and don’t want any modifications, use a const before the variable name in the function parameters! When calling function and don’t want to modify it in any way, then can have the option to make it constant
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

Unformatted text preview: %s only reads up to a whitespace! Will discard everything afterwards % o ^ prefaces the list of inadmissible characters o contain the admissible and/or inadmissible characters o Ignores leading whitespace %10[^\n] will only accept until 10, and then reads until new line. COUNTS WHITESPACE IN THE FIRST 10!!! EOF line at the end of a file While (fscanf(fp, “%60[^\n]%*c != EOF) Fprintf is formatted Puts() is Unformatted if successful, will always return a non-negative value Printf(“%d”, puts(name)); if successful, will return a non-negative number Putting inside the printf the return value of a function can help with debugging...
View Full Document

  • Fall '10
  • michaelhedenreich

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors