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

Replies

- page 1
Oldest  Newest  Rating
0 c student · January 4, 2015
you will need to locate the directory you saved your program in

if you are on windows:
in that folder, shift-right-click on white space and click "Open command prompt here", then proceed to type in the following:
[your program name] < [your text file name]

note that they must be in the same folder and must include the extension as well, such as .txt if there is one.

if you are on mac/linux:
open terminal, change your working directory into the directory of your saved program using the cd command, then type the following:
./[your program name] < [your text file name]

again, note that they must be in the same folder and must include the extension as well, such as .txt if there is one.
0 Nishant Tadvi · January 1, 2015
thx for giving challenge I will soon try it and give result.
0 Nishant Tadvi · January 1, 2015
thx for giving challenge I will soon try it and give result.
0 Doina Doinitza · January 4, 2015
got it. thx
0 Lazar Bulic · January 24, 2015
And here is the answer: 


#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[SIZE-1], upper[SIZE-1], *l, *u, n = SIZE;
    l = lower;
    u = upper;
    FILE *open;

    open = fopen(argv[1], "r");
    if(open == NULL){
        printf("File wasn't opened correcty!");
        return 1;
    }
    while(n--){
        *l++ = 0;
        *u++ = 0;
    }

    while(fscanf(open,"%s",str) != EOF){
            s = str;
            while(*s != NULL){
            if(isupper(*s))
                upper[(int)*s - 'A']++;
            if(islower(*s))
                lower[(int)*s - 'a']++;
            s++;
            }
    }
    for(n=0; n<SIZE; n++){
        printf("%c: %d %c: %d\n", n + 'a', lower[n], n + 'A', upper[n]);
    }
    return 0;
}
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 ----------

http://pastebin.com/YrbChDuM
---------- /spoiler ----------
0 c student · December 29, 2014
i have a challenge for you.  this task is called a frequency analysis and what i challenge you to do is to create a program which counts all of the letters in a given text file, that is, both upper and lower cases are counted separately.   i will show you what i mean.

this is a sample of my text file:
http://i.imgur.com/cwJ9j48.png

and here is my result (note: you will need to pass in a text file as i have shown: [your program] < [your text file]):
http://i.imgur.com/SdiyLzz.png

good luck
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){
            if(isupper(*s))
                upper[(int)*s - 'A']++;
            else if(islower(*s))
                lower[(int)*s - 'a']++;
            s++;
            }
    }
    for(n=0; n<SIZE; n++){
        printf("%c: %d %c: %d\n", n + 'a', lower[n], n + 'A', upper[n]);
    }
    close(open);
    free(lower);
    free(upper);
    return 0;
}
0 Dinar Dude · January 2, 2015
Here are some challenges you could try: http://www.reddit.com/r/dailyprogrammer
0 Darsh Patel · January 17, 2015
Can you make it and reply me that source code on this page?
  • 1
  • 2

C

107,102 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator