Thread: Printing Functions in Succession only if true

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    1

    Printing Functions in Succession only if true

    Hi there,

    I cannot post code here (it is confidential). My problem is that i'm trying to print functions based on whether their conditions are true. For example, there are multiple functions with conditions and if there are multiple that are true, it would print them all out to an lcd in succession after enter is pressed.

    I am having a hard time grasping how I can do this. My main problem is that the cursor position of where things are printed in the function changes depending on whether it is the only true statement, or the third true statement. This means that the order in which the statement is printed changes depending on how many other function conditions are true.

    Hopefully this makes sense, I'd just like some theory and guidance so I can go on my way. I am not at liberty of sharing code, it's confidential.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Hopefully this makes sense,
    Not entirely. You should invent example code, preferably a complete program that compiles.

    You mention in passing something about an LCD. You also mention something about the cursor position, which is not something that is part of standard C. So apparently you can print things at particular positions on an LCD, and that position changes depending on what has been printed before.

    So here's an example of how to maybe handle the position. However, it's only simulating printing at particular positions by stating which position it would print at.
    Code:
    #include <stdio.h>
    
    void f1(int pos) { printf("f1 at pos: %d\n", pos); }
    
    void f2(int pos) { printf("f2 at pos: %d\n", pos); }
    
    void f3(int pos) { printf("f3 at pos: %d\n", pos); }
    
    int main() {
        int b1 = 1, b2 = 0, b3 = 1;
        int pos = 0;
        if (b1) f1(pos++);
        if (b2) f2(pos++);
        if (b3) f3(pos++);
        return 0;
    }
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing text with functions in this practice problem
    By twigz in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2014, 07:43 AM
  2. Replies: 4
    Last Post: 12-23-2012, 10:41 PM
  3. printing out strings with functions and pointers :(
    By kiwi101 in forum C Programming
    Replies: 7
    Last Post: 10-23-2012, 07:59 AM
  4. seperating initialising and printing of arrays into functions
    By Tom Bombadil in forum C Programming
    Replies: 1
    Last Post: 03-11-2009, 11:47 AM
  5. BeginPaint and GetDC called in succession
    By JasonD in forum Windows Programming
    Replies: 2
    Last Post: 05-23-2003, 12:06 PM

Tags for this Thread