My aim is to create a program that:
1. reads in a string of less than 255 characters from the user into a variable called array1
2. copies array1 into a variable called array2, converting each element of array1 to UPPER CASE
3. prints out the contents of array2

I cant seem to do part 2 or 3 and I do not even know if part 1 is correct! :(

here is my code:
#include <stdio.h>
#include "simpleio.h"    

char array1[256];
char array2[256];
int i;

int main()	
{
	printf("Please enter string of text max 255 characters \n");
	getString(array1,255);
	
	for(i=0; array1[i] != '\0';i++)
	{
		if((array2[i] <= 'a') ||(array2[i] >= 'z'))                           //if value is greater than decimal ascii A convert LOWER to UPPER CASE
	   {
		  array2[i] += 32;			  
	   }
		  array2[i]=array1[i];
		  printf("%c",array2[i]); 
    }
    
	printf("\n");

return 0;
}

any help please. Thanks.

You're close.

This code if((array2[i] <= 'a') ||(array2[i] >= 'z')) says
If the letter is ('a' or less) or letter is ('z' or more) ... Is that what you want?

Rethink this if statement. What are you really trying to look for?

Also I would advise clearing out the contents of array1 and array2. As these arrays are local variables they will contain junk values and this could affect your out put

oh so you would subtract 32 from the ascii table...ooops.

You're close.

This code if((array2[i] <= 'a') ||(array2[i] >= 'z')) says
If the letter is ('a' or less) or letter is ('z' or more) ... Is that what you want?

Rethink this if statement. What are you really trying to look for?

would it be better as:
(if array2<='a' && array2>='z')

You're close.

This code if((array2[i] <= 'a') ||(array2[i] >= 'z')) says
If the letter is ('a' or less) or letter is ('z' or more) ... Is that what you want?

Rethink this if statement. What are you really trying to look for?

Sorry for all the reply's but I realise now! its:

if((array1[i] >= 'a') && (array1[i] <= 'z'))                          
	   
		  array1[i] = array1[i] - 32;

Thanks alot was quite foolish.

2. copies array1 into a variable called array2, converting each element of array1 to UPPER CASE

Just use toupper on all characters in the text. Like:

int i;
   for ( i = 0; array1[i]; ++i )
   {
      array2[i] = toupper(array1[i]);
   }
   array2[i] = '\0';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.