Untitled
unknown
c_cpp
10 months ago
785 B
3
Indexable
#include <stdio.h> #include <string.h> typedef struct { char title[ 50 ]; int page_count; } Book; Book initBook( char title[], int page_count ) { Book newBook; strncpy( newBook.title, title, 49 ); newBook.title[ 49 ] = '\0'; newBook.page_count = page_count; return newBook; } void showBook( Book* book ) { printf( "Title: %s\n", book->title ); printf( "Page count: %d\n", book->page_count ); } void addPages( Book* bookPtr ) { bookPtr->page_count += 10; } int main() { Book myBook = initBook( "Sample Book", 100 ); printf( "Before adding pages:\n" ); showBook( &myBook ); addPages( &myBook ); printf( "After adding pages:\n" ); showBook( &myBook ); return 0; }
Editor is loading...
Leave a Comment