Give me some challenge!!!

+2 Nishant Tadvi · December 29, 2014
Plz give me some new challenge. I have completed whole tutorials. So i want some challenge. If you have then give me i would like to make a new program. thx!!!! 

Post a Reply


- page 2
Oldest  Newest  Rating
0 c student · January 24, 2015
you've attempted to return a value despite main being declared without a return type.

here, you're comparing integer value with pointer value
while(*s != NULL)

there was a reason i said to use file redirection: it's to avoid having to deal with file streaming.  there is a much much simpler way to solve the problem found here: 

---------- spoiler ----------
---------- /spoiler ----------
0 Lazar Bulic · January 24, 2015
Yes there were few mistakes:
while(*s != NULL); 

I use it because it doesn't make any errors while compiling but correct would be 
while(*s != '/0');

Also I forgot to close the file which is the biggest mistake :p

The solution that you provided has the same logic but my declaration of an array with all 0 was poorly executed. 
In the following code i resolved it with calloc :D and got rid of few pointers :)

Also my main has the return type. When the return type isn't defined in code the compiler by default compiles it as int.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SIZE 26
#define MAX_SIZE 1000

main(int argc, char *argv[]){
    char str[MAX_SIZE], *s;
    int *lower, *upper, n;
    lower = (int*)calloc(SIZE-1, sizeof(int));
    upper = (int*)calloc(SIZE-1, sizeof(int));
    FILE *open;

    open = fopen(argv[1], "r");
    if(open == '/0'){
        printf("File wasn't opened correcty!");
        return 1;
    while(fscanf(open,"%s",str) != EOF){
            s = str;
            while(*s != NULL){
                upper[(int)*s - 'A']++;
            else if(islower(*s))
                lower[(int)*s - 'a']++;
    for(n=0; n<SIZE; n++){
        printf("%c: %d %c: %d\n", n + 'a', lower[n], n + 'A', upper[n]);
    return 0;
  • 1
  • 2



One of the most popular languages of all time.

Bucky Roberts Administrator