0% found this document useful (0 votes)
15 views2 pages

Pointers Programtask

The document contains C code that defines a function to read text input and count the number of uppercase and lowercase letters. It takes in pointers to integers, gets a text input from the user, iterates through the characters and increments the counts for each case. It then prints out the number of uppercase and lowercase letters.

Uploaded by

petra710386
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Pointers Programtask

The document contains C code that defines a function to read text input and count the number of uppercase and lowercase letters. It takes in pointers to integers, gets a text input from the user, iterates through the characters and increments the counts for each case. It then prints out the number of uppercase and lowercase letters.

Uploaded by

petra710386
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#define MAXLETTERS 20

void readAndCount(int *pUpper, int *pLower) {


char array[MAXLETTERS + 1];

printf("Enter a text > ");


fgets(array, MAXLETTERS + 1, stdin);

*pUpper = *pLower = 0;

int i = 0;
while(array[i] != '\0') {
if(array[i] >= 'A' && array[i] <= 'Z') {
(*pUpper)++;
} else if(array[i] >= 'a' && array[i] <= 'z') {
(*pLower)++;
}
i++;
}
}

int main() {
int lower, upper;

readAndCount(&upper, &lower);

printf("Number of uppercase letters > %d\n", upper);


printf("Number of lowercase letters > %d\n", lower);

return 0;
}

//TAKE02

// #include <stdio.h>
// #define MAXTEXT 20

// void readAndCount (int *pUpper, int *pLower) {


// char array[MAXTEXT + 1];

// *pUpper = *pLower = 0;

// printf("Enter a text > ");


// fgets(array, MAXTEXT + 1, stdin);

// // for(int i = 0; i < MAXTEXT; i++) {


// // if(array[i] >= 'A' && array[i] <= 'Z') {
// // (*pUpper)++;
// // } else if (array[i] >= 'a' && array[i] <= 'z') {
// // (*pLower)++;
// // }
// // }
// //
// // or
// int i = 0;
// while(array[i] != '\0') {
// if(array[i] >= 'A' && array[i] <= 'Z') {
// (*pUpper)++;
// } else if (array[i] >= 'a' && array[i] <= 'z') {
// (*pLower)++;
// }
// i++;
// }
// }

// int main() {
// int upper, lower;

// readAndCount(&upper, &lower); //pusti pointer na adrese, da on sve


odradi umisto varijabli

// printf("Number of uppercase letters > %d\n", upper);


// printf("Number of lowercase letters > %d\n", lower);

// return 0;
// }

You might also like