GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-May-2009, 22:00
radiorat radiorat is offline
New Member
 
Join Date: May 2009
Posts: 2
radiorat is on a distinguished road

toupper does not work in xcode 3.1.2


Please excuse me if this question has been asked before,i did search first.

under Dev cpp in a C program ,using name=toupper(name); works fine on a PC.
on a Mac using 10.5.7 and xcode 3.2.1 it throws "passing argument 1 of 'toupper' makes integer from pointer without a cast" errors.

Apples man pages are not much help at all( surprise surprise).

anyone have any idea what i am doing wrong?


CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <ctype.h>
#include <wctype.h>


int main(int argc, char *argv[])
{
	char end[3];
	
	char name[3];
	
	
	printf("Enter your name: \n");
	fgets(name, sizeof(name), stdin);
	if (name[strlen(name)-1] == '\n') name[strlen(name)-1] = '\0';
	name = toupper (name);
	
	
	
	
	printf("your name is %s. \n",name);


	
	printf("\nType Enter to exit program: \n");
	fgets(end, sizeof(end), stdin);
	end[strlen(end) -1] = '\0';
	exit;
	
  return 0;
}

  #2  
Old 29-May-2009, 22:44
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: toupper does not work in xcode 3.1.2


You are passing an array of characters to toupper instead of an int. Consider the following:
CPP / C++ / C Code:
#include <ctype.h>

int main () {
        char foo[] = "foo";
        char x = toupper(foo);
        char y = toupper(*foo);
        return 0;
}
And when I compile:
Quote:
Originally Posted by gcc
foo.c: In function 'main':
foo.c:5: warning: passing argument 1 of '__toupper' makes integer from pointer without a cast

toupper only works on a single character at a time, not on an array of them. I'm not sure what PC you used to get this to work, but it should at least have complained with a warning...
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #3  
Old 29-May-2009, 23:48
radiorat radiorat is offline
New Member
 
Join Date: May 2009
Posts: 2
radiorat is on a distinguished road

Re: toupper does not work in xcode 3.1.2


Ah, that would explain it!
Thank you very much.

I am using windows XP with Dev cpp 4.9.9.2 .
its not a very flash ide

Is there a way to take a multiple character string and change it to uppercase?
  #4  
Old 30-May-2009, 06:06
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 221
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: toupper does not work in xcode 3.1.2


Quote:
Originally Posted by radiorat
Is there a way to take a multiple character string and change it to uppercase?

Yes, one character at a time!

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

void convertStringToUpper(char* pstr)
{
    if(pstr != NULL)
    {
	while(*pstr)
	{
	    *pstr = toupper(*pstr);
	    ++pstr;
	}
    }
}

int main()
{
    char a_string[1024];
    printf("Enter a character string: ");
    fgets(a_string, sizeof(a_string)/sizeof(char), stdin);
    a_string[strlen(a_string)-1] = '\0';
    printf("Your string converted to uppercase is:\n\n");
    convertStringToUpper(a_string);
    printf("%s\n", a_string);

    return 0;
}
    

Output:

Code:
bash-3.2$ ./toupper Enter a character string: The quick brown fox jumped over the lazy dogs. Your string converted to uppercase is: THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS. bash-3.2$ ./toupper Enter a character string: A function of X divided by 5 = 42 Your string converted to uppercase is: A FUNCTION OF X DIVIDED BY 5 = 42


MxB
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Work at home. English proofreader needed. $14.50/hour cascade_soft Member Announcements, Advertisements & Offers 0 05-Jun-2006 01:29
Random access files Krazy_yA C Programming Language 6 07-May-2006 02:44
Getting .htaccess files to work Krak Apache Web Server Forum 0 23-Sep-2005 12:39
Programming C with Xcode...plz help tahum C Programming Language 4 07-Mar-2005 11:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:01.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.