The Thread I said I was going to make..... :3

blackneos940

Active Member
Joined
May 16, 2017
Messages
347
Reaction score
207
Credits
332
So anyway, here's the C File called UX_Billfold..... :3 I'd like it if you guys could test it out..... :3 It's FOSS, as what else COULD it be.....?? :3 Maybe if it's well-received, maybe I could get some donations for more Caffeine..... ;3 Here's lookin' at you, ScotsGeek!!..... :3

EDIT: So I can't post .c Files, so I made it a .txt File..... :3 You guys should know what to do from here..... :3 Enjoy!..... ^^

EDIT 2: Here's another one!..... :3 It's called Crushed Candy!..... :3 No, it's not a ripoff of the well-known Mobile and Facebook game..... :) All it is is a FOSS Program that is supposed to put colored dots all over the screen, and do so at random places on the screen, as if you crushed candy with a hammer..... :3 It's in beta too, so..... Of course, it'll be in the .txt format, so you know what to do..... :3 Change it to Crushed_Candy.c , and yada yada..... :3
 

Attachments

  • UX_Billfold.txt
    2.3 KB · Views: 914
  • Crushed_Candy.txt
    1.2 KB · Views: 884
Last edited:


Hey Neos or Stan, I haven't dipped my toes into the C pool, yet, so you'll have to tell me what to do with it/them. :oops:

Wiz
 
@blackneos940 :
Regarding UX_Billfold.c:
UX_Billfold.c fails to compile cleanly.
Here are the errors:
Code:
Jason@JASONPC ~/Projects/linux.org/neo
$ gcc UX_Billfold.c -ouxb -lncurses
UX_Billfold.c: In function ‘main’:
UX_Billfold.c:48:18: error: ‘FILE_LIMIT’ undeclared (first use in this function)
   char file_name[FILE_LIMIT];
                  ^~~~~~~~~~
UX_Billfold.c:48:18: note: each undeclared identifier is reported only once for each function it appears in
UX_Billfold.c:63:1: error: stray ‘\357’ in program
 [m
 ^
UX_Billfold.c:63:2: error: stray ‘\277’ in program
 [01;31m
  ^
UX_Billfold.c:63:3: error: stray ‘\275’ in program
 [01;31m
   ^

The first error (at line 48) is because you haven't defined a value for FILE_LIMIT.
Either #define a value for FILE_LIMIT, or you could #include limits.h and use PATH_MAX instead.

NOTE: There is also FILENAME_MAX, which is part of the ANSI C standard. But from what I understand - it shouldn't be used to size an array because the FILENAME_MAX macro is always defined, even if there is no limit set. And in cases where no limit is imposed, the number will be stupidly large. So PATH_MAX is probably the safer bet, or define your own value for FILE_LIMIT.

Also the variable "file_name" - which is where FILE_LIMIT is used - is actually not used anywhere in your program yet. It looks like UX_Billfold is still very much a WIP.

And the remaining errors are because of a strange UTF-8 character at line 63 - Not sure if that was originally in your file, or if the copy I downloaded from your post was somehow corrupt?

Also, you are including curses.h in UX_Billfold, but you aren't using anything from the ncurses library at the moment. The colours you have set up are just terminal escape sequences.

So because ncurses is not being used - I recommend either:
1. Comment out the line that includes ncurses until you need it
or
2. Remove it entirely.

That way, people won't have to unnecessarily install the ncurses development library in order to build your program. There is no point adding it as a dependency if it is not used.

Regarding Crushed_Candy.c:
That one compiles OK and runs, but it doesn't print a randomised pattern at all. It infinitely repeats the same pattern.

In order to get a randomised pattern, you would need to select a random number somewhere inside the loop. So for example, you could set up some arrays containing your colours and patterns. And then inside your infinite loop - For each line, you could select two random numbers. One for the colour and one for the pattern.
Then you simply print the randomly selected pattern in the randomly selected colour.

Here's a spoiler containing some code:
crush2.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

// Escape sequences for colours
#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"

// Array of colours
// Note: we have 6 colours in our array indexed from 0 to 5
const char* colors[]={ANSI_COLOR_RED, ANSI_COLOR_GREEN, ANSI_COLOR_YELLOW,
   ANSI_COLOR_BLUE, ANSI_COLOR_MAGENTA, ANSI_COLOR_CYAN};

#define DOT ".\n\n\n"
#define DOT_TWO " .   \n   .  \n."
#define DOT_THREE "  .     ."
#define DOT_FOUR "  . . \n "
// Array of 4 patterns, indexed from 0 to 3
const char* patterns[]={DOT, DOT_TWO, DOT_THREE, DOT_FOUR};

int main(void)
{
   srand((unsigned) time(NULL));

   while(1)
   {
       // Pick a random colour for this line
       unsigned int colorIdx=rand()%6;
       // Pick a pattern to print
       unsigned int patternIdx=rand()%4;

       printf( "%s%s", colors[colorIdx], patterns[patternIdx]);
   }

   return EXIT_SUCCESS;
}
To compile:
Code:
gcc crush2.c -ocrush2 -Wall -O2


Here's another way to create a more random pattern:
This picks a random line length for each line (between 0 and 29).
Then for each character, it selects a random value for the colour (between 0 and 9).
If the random number is between 0 and 5, we print a coloured dot.
If the number is greater than 5, we print some spaces.

crush3.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

// Escape sequences for colours
#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"

// Array of colours
// Note: we have 6 colours in our array indexed from 0 to 5
const char* colors[]={ANSI_COLOR_RED, ANSI_COLOR_GREEN, ANSI_COLOR_YELLOW,
   ANSI_COLOR_BLUE, ANSI_COLOR_MAGENTA, ANSI_COLOR_CYAN};

int main(void)
{
   srand((unsigned) time(NULL));
 
   // maximum line length
  const unsigned int LineMax=30;

   // infinite loop
   while(1)
   {
       // Set a random line-length between 0 and 30
       unsigned int lineSize=rand()%LineMax;
       for(unsigned int count=0; count<lineSize; ++count)
       {
           // Pick a random colour for each character in the line
           int colorIdx=rand()%10; // Try playing with this value
           // NOTE: Our random number will be between 0 and 9
           // If the value is between 0 and 5:
           if(colorIdx<6)
               printf( "%s. ", colors[colorIdx]); // print a . in colour
           else // number is out of our colour range
               printf("  "); // print some blank spaces
       }
       printf("\n"); // Terminate the current line
   }

   return EXIT_SUCCESS;
}

To compile:
Code:
gcc crush3.c -ocrush3 -Wall -O2

@blackneos940
In this line:
Code:
int colorIdx=rand()%10;
Using modulus 10 to generate our number - gives us a roughly 50/50 chance of generating a space instead of a coloured dot.
The higher the number you use as a parameter to the modulus operation, the more likely it is that we'll generate a space. So to get a pattern with more spaces in it - use a higher number.
Try using 20, 30, 50 and 100 as parameters to the modulus operation and see the difference it makes to the pattern.


Hey Neos or Stan, I haven't dipped my toes into the C pool, yet, so you'll have to tell me what to do with it/them. :oops:

Wiz

With UX_Billfold.c - wait until neo has fixed his compilation errors.

With Crushed_Candy.c, compile and link using:
Code:
gcc Crushed_Candy.c -oCrushed_Candy -Wall -O2
Note: Capital W in -Wall, capital O in -O2.
Also, Neos crushed candy program runs in an infinite loop, so you will need to press ctrl+c to end the program.

[EDIT]
I've attached a zip file (crush.zip) containing code for both of my examples and a shellscript to build them.
After extracting the directory containing the code, simply cd into the dir and then run ./build.sh to build both examples, then you can run them using ./crush2 or ./crush3.
And again - they run in an infinite loop, so you will need to use ctrl+c to stop them.
I hope they give you some ideas!
[/EDIT]
 

Attachments

  • crush.zip
    1.7 KB · Views: 711
Last edited:
Hey Neos or Stan, I haven't dipped my toes into the C pool, yet, so you'll have to tell me what to do with it/them. :oops:

Before @JasKinasis replied, I had found this simple instruction to compile @blackneos940's original C code... but Jason can tell us if this is bad practice as compared to his instructions. It did work for me, anyway.

Code:
gcc -o Candy Crushed_Candy.c   #creates an executable file named Candy or whatever you name it

Cheers
 
Before @JasKinasis replied, I had found this simple instruction to compile @blackneos940's original C code... but Jason can tell us if this is bad practice as compared to his instructions. It did work for me, anyway.

Code:
gcc -o Candy Crushed_Candy.c   #creates an executable file named Candy or whatever you name it

Cheers


No, that will work just as well!
 
@blackneos940 :
Regarding UX_Billfold.c:
UX_Billfold.c fails to compile cleanly.
Here are the errors:
Code:
Jason@JASONPC ~/Projects/linux.org/neo
$ gcc UX_Billfold.c -ouxb -lncurses
UX_Billfold.c: In function ‘main’:
UX_Billfold.c:48:18: error: ‘FILE_LIMIT’ undeclared (first use in this function)
   char file_name[FILE_LIMIT];
                  ^~~~~~~~~~
UX_Billfold.c:48:18: note: each undeclared identifier is reported only once for each function it appears in
UX_Billfold.c:63:1: error: stray ‘\357’ in program
 [m
 ^
UX_Billfold.c:63:2: error: stray ‘\277’ in program
 [01;31m
  ^
UX_Billfold.c:63:3: error: stray ‘\275’ in program
 [01;31m
   ^

The first error (at line 48) is because you haven't defined a value for FILE_LIMIT.
Either #define a value for FILE_LIMIT, or you could #include limits.h and use PATH_MAX instead.

NOTE: There is also FILENAME_MAX, which is part of the ANSI C standard. But from what I understand - it shouldn't be used to size an array because the FILENAME_MAX macro is always defined, even if there is no limit set. And in cases where no limit is imposed, the number will be stupidly large. So PATH_MAX is probably the safer bet, or define your own value for FILE_LIMIT.

Also the variable "file_name" - which is where FILE_LIMIT is used - is actually not used anywhere in your program yet. It looks like UX_Billfold is still very much a WIP.

And the remaining errors are because of a strange UTF-8 character at line 63 - Not sure if that was originally in your file, or if the copy I downloaded from your post was somehow corrupt?

Also, you are including curses.h in UX_Billfold, but you aren't using anything from the ncurses library at the moment. The colours you have set up are just terminal escape sequences.

So because ncurses is not being used - I recommend either:
1. Comment out the line that includes ncurses until you need it
or
2. Remove it entirely.

That way, people won't have to unnecessarily install the ncurses development library in order to build your program. There is no point adding it as a dependency if it is not used.

Regarding Crushed_Candy.c:
That one compiles OK and runs, but it doesn't print a randomised pattern at all. It infinitely repeats the same pattern.

In order to get a randomised pattern, you would need to select a random number somewhere inside the loop. So for example, you could set up some arrays containing your colours and patterns. And then inside your infinite loop - For each line, you could select two random numbers. One for the colour and one for the pattern.
Then you simply print the randomly selected pattern in the randomly selected colour.

Here's a spoiler containing some code:
crush2.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

// Escape sequences for colours
#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"

// Array of colours
// Note: we have 6 colours in our array indexed from 0 to 5
const char* colors[]={ANSI_COLOR_RED, ANSI_COLOR_GREEN, ANSI_COLOR_YELLOW,
   ANSI_COLOR_BLUE, ANSI_COLOR_MAGENTA, ANSI_COLOR_CYAN};

#define DOT ".\n\n\n"
#define DOT_TWO " .   \n   .  \n."
#define DOT_THREE "  .     ."
#define DOT_FOUR "  . . \n "
// Array of 4 patterns, indexed from 0 to 3
const char* patterns[]={DOT, DOT_TWO, DOT_THREE, DOT_FOUR};

int main(void)
{
   srand((unsigned) time(NULL));

   while(1)
   {
       // Pick a random colour for this line
       unsigned int colorIdx=rand()%6;
       // Pick a pattern to print
       unsigned int patternIdx=rand()%4;

       printf( "%s%s", colors[colorIdx], patterns[patternIdx]);
   }

   return EXIT_SUCCESS;
}
To compile:
Code:
gcc crush2.c -ocrush2 -Wall -O2


Here's another way to create a more random pattern:
This picks a random line length for each line (between 0 and 29).
Then for each character, it selects a random value for the colour (between 0 and 9).
If the random number is between 0 and 5, we print a coloured dot.
If the number is greater than 5, we print some spaces.

crush3.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

// Escape sequences for colours
#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"

// Array of colours
// Note: we have 6 colours in our array indexed from 0 to 5
const char* colors[]={ANSI_COLOR_RED, ANSI_COLOR_GREEN, ANSI_COLOR_YELLOW,
   ANSI_COLOR_BLUE, ANSI_COLOR_MAGENTA, ANSI_COLOR_CYAN};

int main(void)
{
   srand((unsigned) time(NULL));
 
   // maximum line length
  const unsigned int LineMax=30;

   // infinite loop
   while(1)
   {
       // Set a random line-length between 0 and 30
       unsigned int lineSize=rand()%LineMax;
       for(unsigned int count=0; count<lineSize; ++count)
       {
           // Pick a random colour for each character in the line
           int colorIdx=rand()%10; // Try playing with this value
           // NOTE: Our random number will be between 0 and 9
           // If the value is between 0 and 5:
           if(colorIdx<6)
               printf( "%s. ", colors[colorIdx]); // print a . in colour
           else // number is out of our colour range
               printf("  "); // print some blank spaces
       }
       printf("\n"); // Terminate the current line
   }

   return EXIT_SUCCESS;
}

To compile:
Code:
gcc crush3.c -ocrush3 -Wall -O2

@blackneos940
In this line:
Code:
int colorIdx=rand()%10;
Using modulus 10 to generate our number - gives us a roughly 50/50 chance of generating a space instead of a coloured dot.
The higher the number you use as a parameter to the modulus operation, the more likely it is that we'll generate a space. So to get a pattern with more spaces in it - use a higher number.
Try using 20, 30, 50 and 100 as parameters to the modulus operation and see the difference it makes to the pattern.




With UX_Billfold.c - wait until neo has fixed his compilation errors.

With Crushed_Candy.c, compile and link using:
Code:
gcc Crushed_Candy.c -oCrushed_Candy -Wall -O2
Note: Capital W in -Wall, capital O in -O2.
Also, Neos crushed candy program runs in an infinite loop, so you will need to press ctrl+c to end the program.

[EDIT]
I've attached a zip file (crush.zip) containing code for both of my examples and a shellscript to build them.
After extracting the directory containing the code, simply cd into the dir and then run ./build.sh to build both examples, then you can run them using ./crush2 or ./crush3.
And again - they run in an infinite loop, so you will need to use ctrl+c to stop them.
I hope they give you some ideas!
[/EDIT]
Hey good sir!!..... :3 As Scotsgeek said, he and I will work on this Offline, but, I'll download and study your revisions..... :) Man, I REALLY appreciate this, buddy..... :3 Isn't Open Source BEAUTIFUL?..... :3
 
Before @JasKinasis replied, I had found this simple instruction to compile @blackneos940's original C code... but Jason can tell us if this is bad practice as compared to his instructions. It did work for me, anyway.

Code:
gcc -o Candy Crushed_Candy.c   #creates an executable file named Candy or whatever you name it

Cheers
Hey Neos or Stan, I haven't dipped my toes into the C pool, yet, so you'll have to tell me what to do with it/them. :oops:

Wiz
It's ok, buddy..... :3 Since you got some help, you might have seen how easy it truly is..... :3 When I first Compiled a C Program beyond the simple string of Commands, I got confused for SURE..... :(
 
Hey good sir!!..... :3 As Scotsgeek said, he and I will work on this Offline, but, I'll download and study your revisions..... :) Man, I REALLY appreciate this, buddy..... :3 Isn't Open Source BEAUTIFUL?..... :3

No worries!
Always happy to cast a critical eye over some code and help with any programming problems.

BTW: I hope you understand the code in the snippets I posted. If there is anything you don't understand, please feel free to ask!

Great to see you active on the site again. And good luck with the continued development of these projects. I look forward to seeing how they progress!
 
No worries!
Always happy to cast a critical eye over some code and help with any programming problems.

BTW: I hope you understand the code in the snippets I posted. If there is anything you don't understand, please feel free to ask!

Great to see you active on the site again. And good luck with the continued development of these projects. I look forward to seeing how they progress!
Ooops..... :3 I forgot to download your Code revisions!..... XD I'mma download them now and study them!..... :3 I'm ALSO gonna' make a Program that has various modes that all download and index various topics of study into a file or files!..... :3 I shall call it..... Fortress Οypanio!..... :3 Oypanio is a Greek word, which means "rainbow"!..... :3 And it's pronounced Ouranio!..... :3 I got the naming convention from Ace Combat Assault Horizon Legacy, which in turn is based on Ace Combat 2..... There is a re-purposed facility used to house ICBMs called Fortress Intolerance, in a military nation called Northpoint..... :3 Yeah, you can tell I like Ace Combat when I name a Program similar to a place in one of the games..... :3 I'll create a Thread soon when I fill in the blanks, as the Program is not even STARTED yet!..... :3
 
No worries!
Always happy to cast a critical eye over some code and help with any programming problems.

BTW: I hope you understand the code in the snippets I posted. If there is anything you don't understand, please feel free to ask!

Great to see you active on the site again. And good luck with the continued development of these projects. I look forward to seeing how they progress!

Man, that's some good Code, buddy!..... :3 It Compiled cleanly, and it looks more like how I wanted it to look!..... :3 Pop Tarts!!..... :3 Man, I want some Pop Tarts right now....... :\
 

Members online


Top