Search⌘ K
AI Features

String Construction

Explore how to construct strings in C through a challenging puzzle. Learn to analyze code, predict outputs, and enhance your understanding of string handling in C programming.

We'll cover the following...

Puzzle code

Read carefully the code given below:

C++
#include <stdio.h>
int main()
{
char filename[] = "update.txt";
char name[16];
int x;
/* initialize the name[] buffer with dots */
for( x=0; x<16; x++ )
name[x] = '.';
/* extract first part of the filename */
x = 0;
while( filename[x] != '.' ) {
name[x] = filename[x];
x++;
}
/* output result */
printf("Extracted name '%.16s' from '%s'\n", name, filename);
return(0);
}

Your task: Guess the output

Attempt the following test to assess your understanding.

Technical Quiz
1.

What is the expected output of the above code?

A.

Extracted name 'update........' from 'update.txt'

B.

Extracted name 'update ' from 'update.txt'

C.

Extracted name 'update'
from 'update.txt'

D.

Extracted name 'update.'
from 'update.txt'


1 / 1

Let's discuss the code and output together in the next lesson.