Demo entry 6364235

test

   

Submitted by mary on May 15, 2017 at 18:20
Language: Python 3. Code size: 1.0 kB.

#include <stdio.h>
#include <cs50.h>
#
/* small program to practice using our own functions
// in this case - let's create a 2 functions
// one that simply prints a string that is passed
// the other to take an input, process, and return a value
*/
// declare the function ahead of time for the compiler
// this void means nothing is being returned 
// this is called a protype
void print_name (string name);

// this void because there are no arguments being passed in
int main(void)
{
    // call a function called print_name - pass the value of s
    string s = "Kirk";
    print_name(s);
    s = "Spock";
    print_name(s);
    printf("Enter a name please: ");
    s = GetString();
    print_name(s);
    // this just sends a completion code back - used if this particular program
    // is called from another, larger, program
    return 0;
}
// void because it is simply taking input and not returning anything
// 
void print_name(string name)
{
    printf("Hello, %s\n", name);
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).