0% found this document useful (0 votes)
13 views3 pages

PW Test

Uploaded by

articlarticl3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

PW Test

Uploaded by

articlarticl3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Faculty of Sciences

Computer Science Department Academic Year: 2023-2024

Duration : 45 minutes Name :

April 23th, 2024 Student number :

Pw test
Exercise 1 :
 What does the `strcat` function do in C?  Complete this example with `strcat`
...………………………………………………. #include <stdio.h>
#include <string.h>
…………………………………………………..
………………………………………………….. int main() {
…………………………………………………. char dest[20] = "Hello ";
…………………………………………………. char src[] = "world!";
…………………………….;
…………………………………………………. printf("%s\n", dest);

return 0;
}
 Explain the purpose of the `strcmp` function in  Complete this example with ` strcmp`
C. #include <stdio.h>
...………………………………………………. #include <string.h>
………………………………………………….. int main() {
………………………………………………….. char str1[] = "hello";
…………………………………………………. char str2[] = "world";
………………………………………………….
……………………………..;
………………………………………………….
if (result == 0) {
printf("Strings are equal\n");
} else {
printf("Strings are not equal\n");
}

return 0;
}
 Describe the role of the `strlen` function in C  Complete this example with ` strlen`
...………………………………………………. #include <stdio.h>
#include <string.h>
…………………………………………………..
………………………………………………….. int main() {
…………………………………………………. char str[] = "Hello, world!";
…………………………………………………. ……………………………….;
…………………………………………………. printf(" %d\n", length);

return 0;
}

A.Y
Faculty of Sciences
Computer Science Department Academic Year: 2023-2024

 What is the purpose of the `strncpy` function?  Complete this example with ` strncpy `
...……………………………………………. #include <stdio.h>
#include <string.h>
………………………………………………….. int main() {
………………………………………………….. char src[] = "Hello, world!";
…………………………………………………. char dest[20]; // Destination buffer
…………………………………………………. // Copy the first 5 characters from src to dest
…………………………………;
…………………………………………………. dest[5] = '\0';
printf("%s\n", dest);

return 0;
}
Exercise 2 :
Let T be an array containing the description of cars in a car park. A car is described by the following fields:

- Registration Number (string of size 12): 05 characters for the serial number, 01 character drawn, 01 character
for the category, and 02 characters for the year of construction, 01 character drawn, and 02 characters for the
wilaya number.

example: 02517 - 316 - 26 is the registration number of a car with:

Serial number 02517, drawn, category 3, year 2016, drawn, wilaya of Médéa 26

- Brand (string of size 10).

- Color (string of size 10).

- Number of Horsepower (integer).

- Price (real).

1- Propose a data structure to represent this statement (declaration of types), Next, write the main algorithm.

#include <stdio.h> ……………………………………………………………………………………………………………………….


#include <string.h> ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………….. ………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………….. ………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………….. ………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………….. ………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………….. ………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………….. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ……………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………. ………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………………. return 0;
………………………………………………………………………………………………………………………. }
………………………………………………………………………………………………………………………..

A.Y
Faculty of Sciences
Computer Science Department Academic Year: 2023-2024

A.Y

You might also like