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 02-18-2019, 01:49 AM   #316
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194

Let's try to keep to the thread topic a little more closely, please all.
 
1 members found this post helpful.
Old 02-18-2019, 07:18 AM   #317
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I'll agree that there are different styles of advice here.

I'm trying to be fundamental. Some are quite correctly encouraging you to stick with the curriculum which you are using. Some, including myself at times, are challenging you to think about the impact of what you are doing.

A result is that there seem to be a lot of changes to the specific problem which you are addressing.

This is actually why I've suggested other threads.

Back to the point about thinking.

Where I'm coming from is when I see you very adroitly analyze a difficult Linux system issue, very clearly explain to another OP a full process which they need to follow, and also follow through very well with all that.

It is an excellent example of analytical thinking.

Throughout this thread, many who have challenged you, as I have, are asking you to think analytically about the code as well as the whole topic of software coding, debug, and design. As you know, different people follow different analytical approaches. Different people have different ways to remind their selves about things.

You need to do that. Whatever you do to remember all the complex Linux stuff where you give great advice to others, you need to do that here.

About Reminders:
  1. My 41 year old book entitled, "The C Programming Language", by Brian W. Kernighan and Dennis M. Ritchie. If I grab it down from the bookcase, place it on the bound edge and let it drop open, it falls open to Section 7.13 Conditional Operator. I had a lot of trouble remembering how it worked and always referred to it, back in the day.
  2. I've told you about retaining old code with good examples, you've mentioned you do that. Please continue.
  3. Moving forwards, "my" preference would be that you deal with one example, preferably per thread, and you run it to ground. And then start another thread about a different set of code.
  4. There is no one person who is going to read all 317+ posts in this thread. I know I haven't even though I've posted at least 17 times or so in it.
 
2 members found this post helpful.
Old 02-18-2019, 11:42 PM   #318
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
I'm sorry if my previous posts come off as me saying "that I thought people responding to this thread were calling me stupid". I wasn't trying to say that at all. Sorry once again if that's how it sounded - it wasn't the intention behind it. I was just frustrated with myself more than anything or one else. Because it's very frustrating trying to read stuff and still not knowing why I have to times this by that, or divide this by that, or whatever else, so it's once again not really the code itself, it's the math that's frustrating me. Because I can see why it's important to know at least some math behind it, so I was really trying to say that "I'm just too stupid to know how the maths works, and why I need to do this or that when it comes to applying the math side of things". I do honestly try to read stuff to explain to myself how it works, but I just don't get the math behind it.

I still don't honestly know if I'll continue with trying to learn C or not. I would like to, but it's really frustrating not being able to do the exercises in the book that involve maths I don't understand. The code for the most part does make a lot of sense - it's just the maths behind it that doesn't.

I'll still use this thread if I do have anything to post in relation to learning C. As, even if others don't read every single post in this thread, it could still be quite useful, and people can still skim through it and just read the posts that are relevant to them. And if it's still in relation to learning C, I think it's better it's in the one place, rather than spread out over possibly several threads.

I'll have a look at the link posted by Mechanikx in post #184 (being this link), and see if that might help. I don't know where to even begin with it having a quick look at it before though. And it's probably going to take a while to get anywhere with that, so it might be a while before I can do any of the exercises I skipped, assuming I decide to try and do them later on.

RT, I'm not angry or anything with you, sorry if it appeared that way. If I'm pissed of with anyone, that's *not* anyone that's responded to this thread. I didn't mean for it to come across that way, it was just frustrating trying to understand what you were saying about the math etc, and still not understanding it, and my mind going blank with it when trying to figure out how to do the exercises in the C book I was following.

Thanks a lot again to everyone that's responded.
 
Old 02-20-2019, 07:35 PM   #319
Mechanikx
Member
 
Registered: Jul 2018
Distribution: Slackware
Posts: 351

Rep: Reputation: 258Reputation: 258Reputation: 258
Don't give up just yet.

One of the great things about C is it allows you to interact with your machine at a lower level. For the most part this is going to require the understanding of certain math. However, this doesn't mean you still can't program in C without having strong math skills. It's perfectly possible to write programs, not just basic ones but advanced ones, that don't require strong math skills. I think you should continue to build on that for now. By advanced I mean using pointers, structures, etc.

I think one of the problems is (and we all face this problem in life) that although you know you want to learn C you really don't know if you're going to like it until you've learnt it. It's pretty much like that with everything in life. You don't know until you try.

So, here's my advice: Forget about the math for right now, including the math centered exercises. Forget about the lower level aspects of C that require an understanding of math. Focus on things like looping, decision-making, pointers, structures, the preprocessor, etc. Have fun learning and creating. Then once you feel you know the C language ask yourself if programming in C is something you really want to do. If it is then that will be the driving force for you to learn a topic that you don't care for like math. See, right now you can't really have that motivation because you really don't know if you're going to like C.

What I'm trying to say is if the frustration with math is enough for you to give up on C then I think the only option you have (besides quitting or risk studying math and then finding out C isn't for you) is you should just learn as much about C as you can without the math and take it from there. The disadvantage of this approach is you're naturally going to be missing some pieces. But I think by the end you will have enough information to be able to decide if you want to go searching for those missing pieces.

I'm reading a book right now called "C Primer Plus" by Stephen Prata (what's with all these C programming authors named Stephen? lol) and although I only just finished chapter 4 I think it's a really great book. In contrast to Kochan he uses a teaching method called the "Spiral method" where you're introduced to a lot of concepts at once and they are explained to you a bit at a time. Which has the advantage of getting a better feel for the language right off the bat. So far there's a lot less math than the Kochan book. There's also more background information in this book and it has increased my knowledge quite a bit already. I was hesitant to recommend this book because A.) I haven't read the whole thing. B.) I felt like I would be throwing a wrench into the works and C.) I know you mentioned you can't afford to pay for a book right now and I couldn't find any "other" versions available on-line.
 
3 members found this post helpful.
Old 02-21-2019, 10:36 PM   #320
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thanks Mechanikx.

While I do want to try and improve my maths skills, I can't help but think you have a very good point there. As it would be a shame to find out after doing a lot of work on my maths skills, that I don't like C enough to want to continue with it. As I said before, it's not really the C code that's particularly difficult, it's the math behind it that gets me.

I wanted to learn C because I like to the idea of being able to interact with the machine at a lower level. Because obviously with things like Python, it's an interpreted language, therefore it's the Python interpreter in that case that actually deals with the machine, and therefore not the programmer. I'd rather be able to go deeper than that.

I haven't decided to give up yet per se. I'm still considering what exactly I should do. While I was thinking about deleting the code I've written so far, I decided against doing that, and still have it. Because I thought "well, if I did decide to just try and learn what I can, and I delete what I've done, it would be a real shame", so I didn't.

I guess I'll just see what I can do, and just do whatever I can, and then decide for final if I want to continue with it or not. I don't really have any better ideas than what you suggested right now anyway. Thanks again.
 
1 members found this post helpful.
Old 02-22-2019, 05:52 PM   #321
Mechanikx
Member
 
Registered: Jul 2018
Distribution: Slackware
Posts: 351

Rep: Reputation: 258Reputation: 258Reputation: 258
You're welcome.

I hope you stick with it

Look forward to the day when you put your ear to the unix shell and you can hear the C *groan* :P

Last edited by Mechanikx; 02-22-2019 at 06:05 PM. Reason: Added a hilarious comment.
 
2 members found this post helpful.
Old 02-23-2019, 02:21 AM   #322
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
do not delete what you wrote. Just save it. Probably you will need it later....
Learning c is not equal to learn math. I would rather say you need to understand the logic how it works. C is relatively simple (comparing to C++ or python for example). And you do not need to learn everything about C, just step by step the tricks what you actually need (to solve your current issue).
By the way, you started this thread at about 3 month ago, believe me, it is not enough to learn it (not for you, for anyone).
 
4 members found this post helpful.
Old 02-23-2019, 03:51 AM   #323
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
jsb... I think you're learning at a faster rate than me. Please remember there's no harm in taking a break from something, especially when you get to the point of feeling so frustrated that you're thinking about quitting.

Quote:
As it would be a shame to find out after doing a lot of work on my maths skills, that I don't like C enough to want to continue with it. As I said before, it's not really the C code that's particularly difficult, it's the math behind it that gets me.
You said you like my rmw program. I'd suggest browsing/skimming through the code sometime. You notice how very little math I use? I know you won't understand all the code from it at this time, but that's not important. You can also join the Riot chat room and ask me questions there about any specific sections of code, if the mood strikes you.

If you'd rather study code that is more expertly developed, you may want to browse the source for the GNU CoreUtils. Again, not important that you understand it all, but it may help give you some extra perspective.
 
2 members found this post helpful.
Old 02-26-2019, 11:08 PM   #324
Mill J
Senior Member
 
Registered: Feb 2017
Location: @127.0.0.1
Distribution: Mint, Void, MX, Haiku, PMOS, Plasma Mobile, and many others
Posts: 1,258
Blog Entries: 2

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
I've been out of this thread for a while, so I figure somebody else mentioned this already, but here goes... I think a person needs a piece of their own software as a goal to make learning enjoyable. For example most people write a calculator(jsbcalc ) to learn basic math, folder viewer for file/folder r/w, etc. The point is designing your own simple app and implementing it function by function, doing research on one piece at a time. When you have an end result in mind it's much easier to understand. You'll probably spend plenty of time surfing the web.

C can be used without learning all the advanced stuff. And if you need something advanced in your program, it'll be much easier to learn, because now you have a reason.


return 0;
 
4 members found this post helpful.
Old 03-08-2019, 07:37 AM   #325
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Thanks again guys.

Sorry for the late reply, I've been at little busy over the past week, and I wanted to give enough time for people to respond.

Anyhow, I do still want to learn C, and other than over the past week, I've still been reading the chapters in the C book. Although I'm yet to figure out why if I only have one function it gets called no problem, but if I have more than one, and I put printf statements, etc in the functions themselves, I don't see any output from them. But if I have the same printf statements in main(), it works fine. I've still got all of the code I wrote before, and I'll have a look at other people's code soon as well.

I was thinking when and if I know enough I could write something that's a GUI for ffmpeg, given what I was saying here.

Thanks for everyone's help once again.
 
Old 03-08-2019, 08:00 AM   #326
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
The best things to do here to get any real feedback on your comments:
Quote:
Originally Posted by jsbjsb001 View Post
I'm yet to figure out why if I only have one function it gets called no problem
Quote:
Originally Posted by jsbjsb001 View Post
But if I have the same printf statements in main(), it works fine.
Show these examples of code where it works, and indicate any outputs which occurred.
Quote:
Originally Posted by jsbjsb001 View Post
but if I have more than one, and I put printf statements, etc in the functions themselves, I don't see any output from them.
Show this example code where it doesn't work, and any outputs which occurred, or note that they didn't occur.
 
1 members found this post helpful.
Old 03-08-2019, 08:26 PM   #327
Mill J
Senior Member
 
Registered: Feb 2017
Location: @127.0.0.1
Distribution: Mint, Void, MX, Haiku, PMOS, Plasma Mobile, and many others
Posts: 1,258
Blog Entries: 2

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Quote:
Originally Posted by jsbjsb001 View Post
I was thinking when and if I know enough I could write something that's a GUI for ffmpeg, given what I was saying here.
That sounds like a goal, and a great one at that.

My ?

I'd start by breaking down the whole thing into several sections.

1, I'd probably write a simple cli app with a while loop menu allowing me to select different functions. Then I'd name the menu entries to something I envision in the gui app and write placeholder functions(simple printf confirmation) to match.

2, Read lots of samples and figure out the ffmpeg api and how to link against the libraries. Start with the menu app and setup demo file conversions, etc one function at a time.

3, select a gui toolkit, and do the hello world thing. Then start figuring out the buttons and how to catch events. Start calling functions I wrote earlier.

4, spend the rest of my life polishing it up ... almost.


As rt mentioned above, posting that problematic code should give us an idea on how to help you figure it out.
 
1 members found this post helpful.
Old 03-09-2019, 12:40 AM   #328
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
I do want to write at least a simple GUI for ffmpeg, starting with a command-line one seems like a good idea though. I like QWinFF's interface, so something simple like that, without too many dependencies would be good. As I hate trying to compile and install something that has a stack of different dependencies myself. So I'd like to write something that's simple to use, but without the bloat and unnecessary dependencies. Thanks Mill J for your help.

Quote:
Originally Posted by rtmistler View Post
The best things to do here to get any real feedback on your comments: Show these examples of code where it works, and indicate any outputs which occurred. Show this example code where it doesn't work, and any outputs which occurred, or note that they didn't occur.
Below is the code where I pass the results of my variables (in my functions) to the main() function, and I get the output I'm expecting. Thanks for your help RT.

Here's the code anyways;

Code:
#include <stdio.h>

int userInput();
float staticFunction();

int userInput(int enteredNumber)
{
    puts("Enter a number: ");
    scanf("%i", &enteredNumber);
    //printf("Entered Number is: %i\n", enteredNumber);
    
    return (enteredNumber);
                
}

float staticFunction()
{
        
    static float staticFunctionVar = 1 + 4;
    //printf("Value of staticFunctionVar: %f\n", staticFunctionVar);
        
    return (staticFunctionVar);
            
}

int main(void)
{
          
    int userInput();
    float staticFunction();
    
    printf("Entered Number is: %i\n", userInput(0));
    printf("Value of staticFunctionVar: %f\n", staticFunction(0));
    puts("Returned to main() function"); 
   
    return 0;

}
This is the output:

Code:
[james@jamespc devel]$ ./staticVar_function_practice 
Enter a number: 
6
Entered Number is: 6
Value of staticFunctionVar: 5.000000
Returned to main() function
But if I comment out the printf statements in main(), and then uncomment them in my two functions, the output from the functions themselves simply doesn't happen. I'm not really sure why though.

Here's the code:

Code:
#include <stdio.h>

int userInput();
float staticFunction();

int userInput(int enteredNumber)
{
    puts("Enter a number: ");
    scanf("%i", &enteredNumber);
    printf("Entered Number is: %i\n", enteredNumber);
    
    //return (enteredNumber);
    return 0;
                
}

float staticFunction()
{
        
    static float staticFunctionVar = 1 + 4;
    printf("Value of staticFunctionVar: %f\n", staticFunctionVar);
        
    //return (staticFunctionVar);
    return 0;        
}

int main(void)
{
          
    int userInput();
    float staticFunction();
    
    //printf("Entered Number is: %i\n", userInput(0));
    //printf("Value of staticFunctionVar: %f\n", staticFunction(0));
    puts("Returned to main() function"); 
   
    return 0;

}
This is what I get when I run it:

Code:
[james@jamespc devel]$ ./staticVar_function_practice 
Returned to main() function
 
Old 03-09-2019, 02:24 AM   #329
Mechanikx
Member
 
Registered: Jul 2018
Distribution: Slackware
Posts: 351

Rep: Reputation: 258Reputation: 258Reputation: 258
@jsbjsb001 and @rtmistler

I hope you two don't mind me jumping in here Glad to see you're still at it jsbjsb001!

Here is your main function:

Code:
int main(void)
{
          
    int userInput();
    float staticFunction();
    
    //printf("Entered Number is: %i\n", userInput(0));
    //printf("Value of staticFunctionVar: %f\n", staticFunction(0));
    puts("Returned to main() function"); 
   
    return 0;

}
These are not function calls but rather function prototype declarations (bolded). The place you have function calls are the arguments for the printf functions in main, which have been commented out so those two functions aren't being called (red). That is why your second example is not producing the same output as your first.

I hope you don't mind me pointing out a couple of things.

Only in the header of 'userInput' is a parameter declared but in its prototype declaration a parameter is not declared. You want to make sure these match.

'staticFunction' has been passed a value when it hasn't been defined or declared to have a parameter.

To show you what I mean (I added the bolded parts):

Code:
#include <stdio.h>

int userInput(int enteredNumber);
float staticFunction(type nameOfParameter);

int userInput(int enteredNumber)
{
    puts("Enter a number: ");
    scanf("%i", &enteredNumber);
    //printf("Entered Number is: %i\n", enteredNumber);
    
    return (enteredNumber);
                
}

float staticFunction(type nameOfParameter)
{
        
    static float staticFunctionVar = 1 + 4;
    //printf("Value of staticFunctionVar: %f\n", staticFunctionVar);
        
    return (staticFunctionVar);
            
}

int main(void)
{
          
    int userInput(int enteredNumber);
    float staticFunction(type nameOfParameter);
    
    printf("Entered Number is: %i\n", userInput(0));
    printf("Value of staticFunctionVar: %f\n", staticFunction(0));
    puts("Returned to main() function"); 
   
    return 0;

}
Also it's not necessary to pass the function 'userInput' an argument since the parameter 'enteredNumber' is then overwritten with a value read in from scanf.

Last edited by Mechanikx; 03-09-2019 at 03:13 AM. Reason: Cleaned things up a bit.
 
1 members found this post helpful.
Old 03-09-2019, 09:39 AM   #330
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
I fixed it so I didn't need the printf statements in main(). I was trying to learn more about functions in general, and how they can be called. So once I got them called in the printf statements in main(), I then wanted to just call the functions from main(), and have main() just call the functions, and the functions do the actual work/have the printf statements in them. And learnt in the process I can't have "static" in the function header, so I had to declare it outside of the function header, and replaced that with "void" instead.

Here's what I did;

Code:
#include <stdio.h>

int userInput(int enteredNumber);
float staticFunction(void);

int userInput(int enteredNumber)
{
    
    puts("Enter a number: ");
    scanf("%i", &enteredNumber);
    printf("Entered Number is: %i\n", enteredNumber);
    
    return (enteredNumber);
                    
}

float staticFunction(void)
{
        
    static float staticFunctionVar = 1 + 4;
    printf("Value of staticFunctionVar: %f\n", staticFunctionVar);
        
    return (staticFunctionVar);
           
}

int main(void)
{

    staticFunction();
    userInput(0);

    //printf("Entered Number is: %i\n", userInput(0));
    //printf("Value of staticFunctionVar: %f\n", staticFunction());
    puts("Returned to main() function"); 
   
    return 0;

}
 
1 members found this post helpful.
  


Reply

Tags
c programming, learning c



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
Finally decided to try to get libinput to work Timothy Miller Linux - Hardware 3 01-04-2018 08:04 PM
Decided to try Lubuntu 14.04 on my netbook... pcninja Ubuntu 4 04-20-2014 08:18 PM
Finally decided to get serious & learn a302svt LinuxQuestions.org Member Intro 1 07-19-2007 12:27 PM
Decided to try Debian some guidance required ninadb Debian 2 08-20-2004 11:40 AM

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

All times are GMT -5. The time now is 04:46 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