Thread: Newb Help needed.

  1. #1
    Registered User
    Join Date
    Jan 2012

    Newb Help needed.

    I've been learning from the book C++ without Fear (first edition) and lost my cd so I have no way of checking how to do the exercise properly.I am having trouble with exercise 7.3.2. The idea is that it converts string to uppercase and the exercise is about including pointers. Problem is, it adds /n to the front of the inputted text and doesn't uppercase the first letter.
    #include "stdafx.h"
    #include <iostream>
    #include <string.h>
    #include <ctype.h>
    using namespace std;
    void convert_to_upper (char *p);
    int main() {
        char s[100];
        cout << "Enter string to convert and press ENTER: ";
        cin.getline(s, 99);
        cout << "The converted string is: /n";
        cout << s;
        return 0;
    void convert_to_upper (char *p) {
        while (*p++)
            *p = toupper(*p);
    Thanks in advance :D
    Last edited by Arthur Popof; 01-31-2012 at 11:17 AM.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    You're incrementing p before you use it in the toupper call. Try
    for ( ; *p; p++)
        *p = toupper(*p);
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > cout << "The converted string is: /n";
    Perhaps you were going for a newline, which would be
    cout << "The converted string is: \n";

    Note the way the / should lean the other way \
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2012
    Yep and yep, thanks!

  5. #5
    Join Date
    Oct 2007
    Inside my computer
    I'd advise you to learn about std::string and std::getline, as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The newb has a newb request
    By Pancakes in forum C Programming
    Replies: 15
    Last Post: 05-27-2011, 08:04 PM
  2. newb help
    By ke121885 in forum C Programming
    Replies: 5
    Last Post: 10-02-2009, 09:53 AM
  3. newb help needed
    By bsnimunf in forum C++ Programming
    Replies: 8
    Last Post: 12-08-2005, 06:55 PM
  4. Im a newb help!
    By Siggy in forum C++ Programming
    Replies: 27
    Last Post: 06-30-2004, 07:35 PM
  5. Please help out a newb
    By Marcos in forum Game Programming
    Replies: 7
    Last Post: 02-02-2003, 01:47 PM