LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2023, 04:17 PM   #31
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869

While testing, make getRandomCharacter to return lower-case letters, then it will be easier to find the (all capital) words.
 
1 members found this post helpful.
Old 01-13-2023, 06:22 PM   #32
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
In your original displayWords function you were trying to regenerate a new set of words which would be different then your other function getFourRandomWords. To display the four words just use a loop:

Code:
// word to be displayed/searched by the user
void displayWords(){
    int loop;
    for(loop = 0; loop < 4; loop++)
        printf("%s ", fourWords[loop]);
    printf("\n");
}
In your other posts about not finding the words just call the display puzzle function to see the results after you place the works to see where they are located since the empty locations will be *. In your place word functions your checking to see if there is an existing letter but not the entire word so sometimes you might see just a random letter.
 
2 members found this post helpful.
Old 01-14-2023, 01:02 AM   #33
however
Member
 
Registered: Jan 2019
Distribution: slackware current
Posts: 497

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
In your original displayWords function you were trying to regenerate a new set of words which would be different then your other function getFourRandomWords. To display the four words just use a loop:

Code:
// word to be displayed/searched by the user
void displayWords(){
    int loop;
    for(loop = 0; loop < 4; loop++)
        printf("%s ", fourWords[loop]);
    printf("\n");
}
In your other posts about not finding the words just call the display puzzle function to see the results after you place the works to see where they are located since the empty locations will be *. In your place word functions your checking to see if there is an existing letter but not the entire word so sometimes you might see just a random letter.
Thank you!
it worked. And your explanation coupled with the example was much easier to understand.

(i didn't even remember that I had a char fourWords...)

I guess I have had enough C lessons for this week and my old(ish) brain feels like it has climbed the Everest. I will spend the next few weeks/months trying to learn how the user/program will input/take the coordinate of each word and perhaps highlight it if correct. Any pointers on what I need to look up?

Once more, thank you everyone on this. Now i remember why I chose the Linux community and joined LinuxQuestions
 
2 members found this post helpful.
Old 01-14-2023, 07:04 AM   #34
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
One fairly simple way to highlight would be to use ANSI escape code sequences. You can change the text and background colors.
Code:
  printf("\033[1;31m");  // change text color to red
  printf("%c ", puzzle[i][j]); // print puzzle letter in red
  printf("\033[0m"); // reset color back to default
https://en.wikipedia.org/wiki/ANSI_escape_code

The difficult part is figuring a way to keep track which letters were selected.

Last edited by michaelk; 01-14-2023 at 07:06 AM.
 
Old 01-14-2023, 12:31 PM   #35
however
Member
 
Registered: Jan 2019
Distribution: slackware current
Posts: 497

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
One fairly simple way to highlight would be to use ANSI escape code sequences. You can change the text and background colors.
Code:
  printf("\033[1;31m");  // change text color to red
  printf("%c ", puzzle[i][j]); // print puzzle letter in red
  printf("\033[0m"); // reset color back to default
https://en.wikipedia.org/wiki/ANSI_escape_code

The difficult part is figuring a way to keep track which letters were selected.
YAY! Not bragging my (non)extensive coding/web-search skills {sarcasm} but I had done it all on my own
Code:
// word to be displayed/searched by the user in red colour
void displayWords(){
    int loop;
    printf("\033[1;31m");
    for(loop = 0; loop < 4; loop++)
        printf("%s ", fourWords[loop]);
    printf("\n");
}

//Create a user-interactive menu in normal/console colours
void mainMenu()
{
    printf("\033[0;32m");
    char menuChoice;
    do
    {
     ........
I only wanted to color the words and not the entire puzzle, console colours are more 'catching'!

As always, thank you!
 
Old 01-15-2023, 11:38 AM   #36
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by however View Post
I wonder whether people forget the meaning of 'beginner' once they specialize on a subject whether it being medicine or feeding chicken.
Agreed. Back when I was a TA (in a previous life) I initially found it difficult to see problems the same way as a newcomer to the subject was seeing them.

I sometimes wonder if it wouldn't make sense for some fora to have a "newbie" sub-forum where the real beginners' questions can be posted. Or perhaps "Newbie" could have all those sub-fora -- Newbie-Software, Newbie-Hardware, etc. -- rather like those under "Distributions". I suspect, though, that making things that fine-grained might be a pain for the moderators to manage.

Cheers...
 
Old 01-15-2023, 11:59 AM   #37
however
Member
 
Registered: Jan 2019
Distribution: slackware current
Posts: 497

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rnturn View Post
Agreed. Back when I was a TA (in a previous life) I initially found it difficult to see problems the same way as a newcomer to the subject was seeing them.

I sometimes wonder if it wouldn't make sense for some fora to have a "newbie" sub-forum where the real beginners' questions can be posted. Or perhaps "Newbie" could have all those sub-fora -- Newbie-Software, Newbie-Hardware, etc. -- rather like those under "Distributions". I suspect, though, that making things that fine-grained might be a pain for the moderators to manage.

Cheers...
Although it sounds like an excellent idea, it has its drawbacks. The main one being that it will mostly be newbies-halping-newbies (like the blinding leading the deaf) and real help would be hard to get as well as real learning opportunities.

Perhaps the issue is more at personal/individual level. I know there tens , if not hundreds of hard-core developers in this forum and they hardly ever reply or engage in any of my questions; and, that's absolutely fine. I really understand and don't expect their involvement.

But then having the so called, I-know-it-all, who prefers to type an A4 size of lines, explaining how something should be, to a beginner who took almost 3months to type (and copy&paste) 100 lines of whatever it's really showing how either they do-not-know-anything-at-all or they are very arrogant teachers. My analogy would be: trying to teach university level to primary school pupils.

There is never a bad student, only bad teachers (I love this phrase, I just don't remember who is it from)

Happy coding!

p.s: by the way, what is a TA?

Last edited by however; 01-15-2023 at 12:02 PM.
 
Old 01-16-2023, 11:26 PM   #38
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
TA -Technical Assistant: often a person doing an advance degree (Masters or PhD) who assists in the undergrad 'lab' for money.

BTW, I also agree with dumping the IDE (for now anyway).
You're trying to learn >1 tool at the same time that way and you don't always know which is which.
Simplify, simplify
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
to grep 100 letters out of 500 letters on certain criteria l_ravi69 Programming 3 10-13-2013 11:37 AM
Can't stop fast typing double letters from "skipping" one of the letters. Lola Kews Ubuntu 3 04-20-2013 03:21 PM
Random device letters assigned on Ubuntu 8.04? brianpbarnes Linux - Hardware 1 12-04-2008 06:26 PM
random letters pixellany Programming 15 07-14-2007 08:05 AM
Broken Fedora Version? (National letters get messed up, random times) blackman890 Fedora 1 06-27-2005 07:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration