Jump to content


Check out our Community Blogs

annalake123

Member Since 17 Nov 2015
Offline Last Active Aug 04 2016 12:12 AM
-----

Posts I've Made

In Topic: The magic and flexibility of printf (part 2)

27 January 2016 - 01:53 AM

#define PRINTCHAR(c) putchar(c)
#define MAXLEN 256

// Write a printf function which simulates printf() in C.
int formatAndPrintString(char *pcFmt, va_list lList)
{
    //Holds the number of characters printed, 0 on error
    int nChars = 0;

while(*pcFmt != '\0')
{
    if(*pcFmt == '%')
    {
        pcFmt++;

        int iTemp = 0;
        char acTemp[MAXLEN] = ""; 
        char *pcTemp = NULL, cTemp = 0;

        switch (*pcFmt)
        {
        case 'd':
            iTemp = va_arg(lList, int);
            itoa(iTemp, acTemp, 10); 

            for(int i = 0; i < strlen(acTemp); i++)
            {
                PRINTCHAR(acTemp[i]); nChars++;
            }
            break;
        case 's':
            pcTemp = va_arg(lList, char*);

            while(*pcTemp != '\0')
            {
                PRINTCHAR(*pcTemp); nChars++;
                pcTemp++;
            }
            break;
        case 'c':
            cTemp = va_arg(lList, int);  
            PRINTCHAR(cTemp);
            nChars++;
            break;
       default:
          break;
       }
       pcFmt++;
    }
    else 
    // print the char to console
    {
       PRINTCHAR(*pcFmt);
       pcFmt++; nChars++;
    }
}
return nChars;
}

// Print function identical to printf() in stdio.h
int printfunc(char *pcFormat, ...)
{
    if(!pcFormat)
    {
        return 0;
    }

    va_list lList;
    va_start(lList, pcFormat);

    return(formatAndPrintString(pcFormat, lList));
}

200-120 Pass4sure

 


In Topic: The magic and flexibility of printf (part 2)

17 November 2015 - 02:11 AM

Answer as a new post .

1) What are the rules when writing pseudocode?

2) What is the difference between pseudocode and a programming language VB?

3) [If you’ve done GCSE Computing] For the following pseudocode write a VB.NET equivalent:

for x from 1 to 7 inclusive
add x to total
loop
print total

4) Write pseudocode for the following problem:

Find the average of 4 numbers and display it
 

Hand Car Wash Sydney


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download