Library Functions. General Questions
|
|
- Gilbert Hood
- 6 years ago
- Views:
Transcription
1 1 Library Functions General Questions 1. What will the function rewind() do? A. Reposition the file pointer to a character reverse. B. Reposition the file pointer stream to end of file. C. Reposition the file pointer to begining of that line. D. Reposition the file pointer to begining of file. Answer: Option D rewind() takes the file pointer to the beginning of the file. so that the next I/O operation will take place at the beginning of the file. Example: rewind(filepointer); 2. Input/output function prototypes and macros are defined in which header file? A. conio.h B. stdlib.h C. stdio.h D. dos.h Answer: Option C stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations. 3. Which standard library function will you use to find the last occurance of a character in a string in C? A. strnchar() B. strchar() C. strrchar() D. strrchr() Answer: Option D strrchr() returns a pointer to the last occurrence of character in a string. Example: #include <stdio.h> #include <string.h>
2 2 char str[30] = " "; printf("the last position of '2' is %d.\n", strrchr(str, '2') - str); Output: The last position of '2' is What is stderr? A. standard error B. standard error types C. standard error streams D. standard error definitions Answer: Option C The standard error(stderr) stream is the default destination for error messages and other diagnostic warnings. Like stdout, it is usually also directed to the output device of the standard console (generally, the screen). 5. Does there any function exist to convert the int or float to a string? A. Yes B.No 1. itoa() converts an integer to a string. 2. ltoa() converts a long to a string. 3. ultoa() converts an unsigned long to a string. 4. sprintf() sends formatted output to a string, so it can be used to convert any type of values to string type. #include<stdlib.h> int main(void) int num1 = 12345; float num2 = 5.12; char str1[20]; char str2[20]; itoa(num1, str1, 10); /* 10 radix value */ printf("integer = %d string = %s \n", num1, str1); sprintf(str2, "%f", num2); printf("float = %f string = %s", num2, str2);
3 3 // Output: // integer = string = // float = string = What is the purpose of fflush() function. A. flushes all streams and specified streams. B. flushes only specified stream. C. flushes input/output buffer. D. flushes file buffer. "fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell command for redirecting output to a pipe or coprocess. Example: fflush(filepointer); fflush(null); flushes all streams. 7. Can you use the fprintf() to display the output on the screen? A. Yes B.No Do like this fprintf(stdout, "%s %d %f", str, i, a); 8. What will the function randomize() do in Turbo C under DOS? A. returns a random number. B. returns a random number generator in the specified range. C. returns a random number generator with a random value based on time. D. return a random number with a given seed value. Answer: Option C The randomize() function initializes the random number generator with a random value based on time. You can try the sample program given below in Turbo-C, it may not work as expected in other compilers. /* Prints a random number in the range 0 to 99 */ #include <stdlib.h>
4 4 #include <stdio.h> #include <time.h> int main(void) randomize(); printf("random number in the 0-99 range: %d\n", random (100)); Find Output of Program 1. What will be the output of the program? int i; i = printf("how r u\n"); i = printf("%d\n", i); printf("%d\n", i); How r u A. 7 2 How r u C. 1 1 How r u B. 8 2 D. Error: cannot assign printf to variable In the program, printf() returns the number of charecters printed on the console i = printf("how r u\n"); This line prints "How r u" with a new line character and returns the length of string printed then assign it to variable i. So i = 8 (length of '\n' is 1). i = printf("%d\n", i); In the previous step the value of i is 8. So it prints "8" with a new line character and returns the length of string printed then assign it to variable i. So i = 2 (length of '\n' is 1). printf("%d\n", i); In the previous step the value of i is 2. So it prints "2". 2. What will be the output of the program? #include<math.h> float i = 2.5; printf("%f, %d", floor(i), ceil(i));
5 A. 2, 3 B , 3 C , 0 D. 2, 0 Answer: Option C Both ceil() and floor() return the integer found as a double. 5 floor(2.5) returns the largest integral value(round down) that is not greater than 2.5. So output is ceil(2.5) returns 3, while converting the double to int it returns '0'. So, the output is ' , 0'. 3. What will be the output of the program? int i; i = scanf("%d %d", &i, &i); printf("%d\n", i); A. 1 B. 2 C. Garbage value D. Error: cannot assign scanf to variable scanf() returns the number of variables to which you are provding the input. i = scanf("%d %d", &i, &i); Here Scanf() returns 2. So i = 2. printf("%d\n", i); Here it prints What will be the output of the program? int i; char c; for(i=1; i<=5; i++) scanf("%c", &c); /* given input is 'b' */ ungetc(c, stdout); printf("%c", c);
6 ungetc(c, stdin); A. bbbb B. bbbbb C. b D. Error in ungetc statement. Answer: Option C The ungetc() function pushes the character c back onto the named input stream, which must be open for reading. This character will be returned on the next call to getc or fread for that stream. One character can be pushed back in all situations. A second call to ungetc without a call to getc will force the previous character to be forgotten What will be the output of the program? #include<stdlib.h> char *i = "55.555"; int result1 = 10; float result2 = ; result1 = result1+atoi(i); result2 = result2+atof(i); printf("%d, %f", result1, result2); A. 55, B. 66, C. 65, D. 55, 55 Answer: Option C Function atoi() converts the string to integer. Function atof() converts the string to float. result1 = result1+atoi(i); Here result1 = 10 + atoi(55.555); result1 = ; result1 = 65; result2 = result2+atof(i); Here result2 = atof(55.555); result2 = ;
7 7 result2 = ; So the output is "65, ". 6. What will be the output of the program? #include<string.h> char dest[] = 97, 97, 0; char src[] = "aaa"; int i; if((i = memcmp(dest, src, 2))==0) printf("got it"); else printf("missed"); A. Missed B. Got it C. Error in memcmp statement D. None of above memcmp compares the first 2 bytes of the blocks dest and src as unsigned chars. So, the ASCII value of 97 is 'a'. if((i = memcmp(dest, src, 2))==0) When comparing the array dest and src as unsigned chars, the first 2 bytes are same in both variables.so memcmp returns '0'. Then, the if(0=0) condition is satisfied. Hence the output is "Got it". 7. What will function gcvt() do? A. Convert vector to integer value B. Convert floating-point number to a string C. Convert 2D array in to 1D array. D. Covert multi Dimensional array to 1D array The gcvt() function converts a floating-point number to a string. It converts given value to a null-terminated string. #include <stdlib.h> #include <stdio.h> int main(void) char str[25];
8 8 double num; int sig = 5; /* significant digits */ /* a regular number */ num = 9.876; gcvt(num, sig, str); printf("string = %s\n", str); /* a negative number */ num = ; gcvt(num, sig, str); printf("string = %s\n", str); /* scientific notation */ num = 0.678e5; gcvt(num, sig, str); printf("string = %s\n", str); return(0); Output: string = string = string = What will be the output of the program? int i; char c; for(i=1; i<=5; i++) scanf("%c", &c); /* given input is 'a' */ printf("%c", c); ungetc(c, stdin); A. aaaa B. aaaaa C. Garbage value. D. Error in ungetc statement. for(i=1; i<=5; i++) Here the for loop runs 5 times. Loop 1: scanf("%c", &c); Here we give 'a' as input. printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement. ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream. Loop 2:
9 Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function. printf("%c", c); Now variable c = 'a'. So it prints the character 'a'. ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream. This above process will be repeated in Loop 3, Loop 4, Loop 5. 9 Point Out Errors 1. Point out the error in the following program. fprintf("sbdsisaikat"); printf("%.ef", 2.0); A. Error: unknown value in printf() statement. B. Error: in fprintf() statement. C. No error and prints "Sbdsisaikat" D. No error and prints "2.0" Declaration Syntax: int fprintf (FILE *stream, const char *format [, argument,...]); Example: fprintf(filestream, "%s %d %s", Name, Age, City); 2. Point out the error in the following program. #include<string.h> char str1[] = "Learn through Sbdsisaikat\0.com", str2[120]; char *p; p = (char*) memccpy(str2, str1, 'i', strlen(str1)); *p = '\0'; printf("%s", str2); A. Error: in memccpy statement B. Error: invalid pointer conversion C. Error: invalid variable declaration D. No error and prints "Learn through Indi"
10 10 Answer: Option D Declaration: void *memccpy(void *dest, const void *src, int c, size_t n); : Copies a block of n bytes from src to dest With memccpy(), the copying stops as soon as either of the following occurs: => the character 'i' is first copied into str2 => n bytes have been copied into str2 3. Point out the error in the following program. char str[] = "Sbdsisaikat"; printf("%.#s %2s", str, str); A. Error: in Array declaration B. Error: printf statement C. Error: unspecified character in printf D. No error Answer: Option D True / False Questions 1. It is necessary that for the string functions to work safely the strings must be terminated with '\0'. A. True B.False C string is a character sequence stored as a one-dimensional character array and terminated with a null character('\0', called NULL in ASCII). The length of a C string is found by searching for the (first) NULL byte. 2. FILE is a structure suitably typedef'd in "stdio.h". A. True B.False
11 11 FILE - a structure containing the information about a file or text stream needed to perform input or output operations on it, including: => a file descriptor, the current stream position, => an end-of-file indicator, => an error indicator, => a pointer to the stream's buffer, if applicable fpos_t - a non-array type capable of uniquely identifying the position of every byte in a file. size_t - an unsigned integer type which is the type of the result of the sizeof operator. 3. ftell() returns the current position of the pointer in a file stream. A. True B.False The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream. Example: #include <stdio.h> int main(void) FILE *stream; stream = fopen("myfile.txt", "w+"); fprintf(stream, "This is a test"); printf("the file pointer is at byte %ld\n", ftell(stream)); fclose(stream); 4. Data written into a file using fwrite() can be read back using fscanf() A. True B.False fwrite() - Unformatted write in to a file. fscanf() - Formatted read from a file. 5. If the two strings are found to be unequal then strcmp returns difference between the first non-matching pair of characters.
12 12 A. True B.False g = strcmp(s1, s2); returns 0 when the strings are equal, a negative integer when s1 is less than s2, or a positive integer if s1 is greater than s2, that strcmp() not only returns -1, 0 and +1, but also other negative or positive values(returns difference between the first non-matching pair of characters between s1 and s2). A possible implementation for strcmp() in "The Standard C Library". int strcmp (const char * s1, const char * s2) for(; *s1 == *s2; ++s1, ++s2) if(*s1 == 0) return *(unsigned char *)s1 < *(unsigned char *)s2? -1 : 1; 1. Is standard library a part of C language? A. Yes B.No The C standard library consists of a set of sections of the ISO C standard which describe a collection of header files and library routines used to implement common operations, such as input/output and string handling, in the C programming language. The C standard library is an interface standard described by a document; it is not an actual library of software routines available for linkage to C programs. 2. Will the program outputs "Sbdsisaikat.com"? #include<string.h> char str1[] = "Sbdsisaikat.com"; char str2[20]; strncpy(str2, str1, 8); printf("%s", str2); A. Yes B.No
13 13 No. It will print something like 'Sbdsisaikat(some garbage values here)'. Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with Sbdsisaikat. 3. The itoa function can convert an integer in decimal, octal or hexadecimal form to a string. A. Yes B.No itoa() takes the integer input value input and converts it to a number in base radix. The resulting number a sequence of base-radix digits. Example: /* itoa() example */ #include <stdio.h> #include <stdlib.h> int main () int no; char buff [50]; printf ("Enter number: "); scanf ("%d",&no); itoa (no,buff,10); printf ("Decimal: %s\n",buff); itoa (no,buff,2); printf ("Binary: %s\n",buff); itoa (no,buff,16); printf ("Hexadecimal: %s\n",buff); Output: Enter a number: 1250 Decimal: 1250 Binary: Hexadecimal: 4e2 4. The prototypes of all standard library string functions are declared in the file string.h. A. Yes B.No
14 14 string.h is the header in the C standard library for the C programming language which contains macro definitions, constants, and declarations of functions and types used not only for string handling but also various memory handling functions. 5. scanf() or atoi() function can be used to convert a string like "436" in to integer. A. Yes B.No scanf is a function that reads data with specified format from a given string stream source. scanf("%d",&number); atoi() convert string to integer. var number; number = atoi("string");
Chapter 8: Character & String. In this chapter, you ll learn about;
Chapter 8: Character & String Principles of Programming In this chapter, you ll learn about; Fundamentals of Strings and Characters The difference between an integer digit and a character digit Character
More informationHuawei Test 3. 1 A card is drawn from a pack of 52 cards. The probability of getting a queen of club or a king of heart is:
Huawei Test 3 1 A card is drawn from a pack of 52 cards. The probability of getting a queen of club or a king of heart is: ( )1 /13 ( )2 /13 ( )1 /26 ( )1 /52 Here, n(s) = 52. Let E = event of getting
More informationCSI 402 Lecture 2 Working with Files (Text and Binary)
CSI 402 Lecture 2 Working with Files (Text and Binary) 1 / 30 AQuickReviewofStandardI/O Recall that #include allows use of printf and scanf functions Example: int i; scanf("%d", &i); printf("value
More informationSolutions to Assessment
Solutions to Assessment 1. In the bad character rule, what are the values of R(P) for the given pattern. CLICKINLINK (Please refer the lecture). Ans: a) C-1,K-10,N-9,I-8,L-2 b) C-1,K-10,N-9,I-8,L-7 c)
More informationStandard C Library Functions
Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of
More informationMode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.
Files Files enable permanent storage of information C performs all input and output, including disk files, by means of streams Stream oriented data files are divided into two categories Formatted data
More informationPointers, Arrays, and Strings. CS449 Spring 2016
Pointers, Arrays, and Strings CS449 Spring 2016 Pointers Pointers are important. Pointers are fun! Pointers Every variable in your program has a memory location. This location can be accessed using & operator.
More informationInput / Output Functions
CSE 2421: Systems I Low-Level Programming and Computer Organization Input / Output Functions Presentation G Read/Study: Reek Chapter 15 Gojko Babić 10-03-2018 Input and Output Functions The stdio.h contain
More informationContent. Input Output Devices File access Function of File I/O Redirection Command-line arguments
File I/O Content Input Output Devices File access Function of File I/O Redirection Command-line arguments UNIX and C language C is a general-purpose, high-level language that was originally developed by
More informationUNIT IV-2. The I/O library functions can be classified into two broad categories:
UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known
More informationCopyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented
More informationInput/Output and the Operating Systems
Input/Output and the Operating Systems Fall 2015 Jinkyu Jeong (jinkyu@skku.edu) 1 I/O Functions Formatted I/O printf( ) and scanf( ) fprintf( ) and fscanf( ) sprintf( ) and sscanf( ) int printf(const char*
More informationComputer Programming: Skills & Concepts (CP) Files in C
CP 20 slide 1 Tuesday 21 November 2017 Computer Programming: Skills & Concepts (CP) Files in C Julian Bradfield Tuesday 21 November 2017 Today s lecture Character oriented I/O (revision) Files and streams
More informationSystems Programming. 08. Standard I/O Library. Alexander Holupirek
Systems Programming 08. Standard I/O Library Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of Konstanz Summer Term 2008 Last lecture:
More informationFloating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions
Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point
More informationIntroduction to string
1 Introduction to string String is a sequence of characters enclosed in double quotes. Normally, it is used for storing data like name, address, city etc. ASCII code is internally used to represent string
More information4) In C, if you pass an array as an argument to a function, what actually gets passed?
Paytm Programming Sample paper: 1) What will be the output of the program? #include int main() } int y=128; const int x=y; printf("%d\n", x); return 0; a. 128 b. Garbage value c. Error d. 0 2)
More informationArrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)
1 Arrays General Questions 1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? A. The element will be set to 0. B. The compiler would
More informationCSci 4061 Introduction to Operating Systems. Input/Output: High-level
CSci 4061 Introduction to Operating Systems Input/Output: High-level I/O Topics First, cover high-level I/O Next, talk about low-level device I/O I/O not part of the C language! High-level I/O Hide device
More informationFundamentals of Programming
Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in
More informationFile (1A) Young Won Lim 11/25/16
File (1A) Copyright (c) 2010-2016 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationUNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.
UNIT-V Unit-5 File Streams Formatted I/O Preprocessor Directives Printf Scanf A file represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf
More informationLecture 03 Bits, Bytes and Data Types
Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics
More informationC mini reference. 5 Binary numbers 12
C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char
More informationMemory Allocation. General Questions
General Questions 1 Memory Allocation 1. Which header file should be included to use functions like malloc() and calloc()? A. memory.h B. stdlib.h C. string.h D. dos.h 2. What function should be used to
More informationComputer Programming Unit v
READING AND WRITING CHARACTERS We can read and write a character on screen using printf() and scanf() function but this is not applicable in all situations. In C programming language some function are
More informationBinghamton University. CS-220 Spring Includes & Streams
Includes & Streams 1 C Pre-Processor C Program Pre-Processor Pre-processed C Program Header Files Header Files 2 #include Two flavors: #include Replace this line with the contents of file abc.h
More informationAdvanced C Programming Topics
Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8
More informationCS201 Lecture 2 GDB, The C Library
CS201 Lecture 2 GDB, The C Library RAOUL RIVAS PORTLAND STATE UNIVERSITY Announcements 2 Multidimensional Dynamically Allocated Arrays Direct access support. Same as Multidimensional Static Arrays No direct
More informationCourse organization. Course introduction ( Week 1)
Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and
More informationComputer Programming: Skills & Concepts (CP) Strings
CP 14 slide 1 Tuesday 31 October 2017 Computer Programming: Skills & Concepts (CP) Strings Ajitha Rajan Tuesday 31 October 2017 Last lecture Input handling char CP 14 slide 2 Tuesday 31 October 2017 Today
More informationComputer Programming: Skills & Concepts (CP1) Files in C. 18th November, 2010
Computer Programming: Skills & Concepts (CP1) Files in C 18th November, 2010 CP1 26 slide 1 18th November, 2010 Today s lecture Character oriented I/O (revision) Files and streams Opening and closing files
More informationSystem Software Experiment 1 Lecture 7
System Software Experiment 1 Lecture 7 spring 2018 Jinkyu Jeong ( jinkyu@skku.edu) Computer Systems Laboratory Sungyunkwan University http://csl.skku.edu SSE3032: System Software Experiment 1, Spring 2018
More informationStream Model of I/O. Basic I/O in C
Stream Model of I/O 1 A stream provides a connection between the process that initializes it and an object, such as a file, which may be viewed as a sequence of data. In the simplest view, a stream object
More informationTopic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional)
Topic 8: I/O Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional) No C language primitives for I/O; all done via function
More informationC PROGRAMMING. Characters and Strings File Processing Exercise
C PROGRAMMING Characters and Strings File Processing Exercise CHARACTERS AND STRINGS A single character defined using the char variable type Character constant is an int value enclosed by single quotes
More information8. Characters, Strings and Files
REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 INPUT/OUTPUT INPUT AND OUTPUT Programs must be able to write data to files or to physical output devices such as displays or printers, and to read in data from files or
More informationC Basics And Concepts Input And Output
C Basics And Concepts Input And Output Report Working group scientific computing Department of informatics Faculty of mathematics, informatics and natural sciences University of Hamburg Written by: Marcus
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationC programming basics T3-1 -
C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of
More informationContents. A Review of C language. Visual C Visual C++ 6.0
A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source
More informationComputer System and programming in C
File Handling in C What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary storage so that the contents of files remain intact
More informationLecture 4. Console input/output operations. 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting
Lecture 4 Console input/output operations 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting Header files: stdio.h conio.h C input/output revolves around
More informationAccessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter
More informationDEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : I / II Section : CSE - 1 & 2 Subject Code : CS6202 Subject Name : Programming and Data Structures-I Degree & Branch : B.E C.S.E. 2 MARK
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 12
BIL 104E Introduction to Scientific and Engineering Computing Lecture 12 Files v.s. Streams In C, a file can refer to a disk file, a terminal, a printer, or a tape drive. In other words, a file represents
More informationBinghamton University. CS-211 Fall Input and Output. Streams and Stream IO
Input and Output Streams and Stream IO 1 Standard Input and Output Need: #include Large list of input and output functions to: Read and write from a stream Open a file and make a stream Close
More informationCMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program
CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationBİL200 TUTORIAL-EXERCISES Objective:
Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that
More informationLecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments
Lecture 7: Files opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 5: Files, I/O 0IGXYVI*MPIW 0 opening/closing files reading/writing
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationWriting an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and
Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()
More informationHigh Performance Programming Programming in C part 1
High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the
More informationMemory Management and
Introduction to Computer and Program Design Lesson 6 Memory Management and File I/O James C.C. Cheng Department of Computer Science National Chiao Tung University Dynamic memory allocation l malloc Syntax:
More informationLectures 5-6: Introduction to C
Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most
More informationUNIX input and output
UNIX input and output Disk files In UNIX a disk file is a finite sequence of bytes, usually stored on some nonvolatile medium. Disk files have names, which are called paths. We won t discuss file naming
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur A complete C program
More informationFundamentals of Programming. Lecture 10 Hamed Rasifard
Fundamentals of Programming Lecture 10 Hamed Rasifard 1 Outline File Input/Output 2 Streams and Files The C I/O system supplies a consistent interface to the programmer independent of the actual device
More informationC Strings. Abdelghani Bellaachia, CSCI 1121 Page: 1
C Strings 1. Objective... 2 2. Introduction... 2 3. String Declaration & Initialization... 2 4. C Built-in String Function... 5 5. Questions/Practice... 13 Abdelghani Bellaachia, CSCI 1121 Page: 1 1. Objective
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationChapter 8 C Characters and Strings
Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()
More informationSWEN-250 Personal SE. Introduction to C
SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the
More informationCSE 230 Intermediate Programming in C and C++ Input/Output and Operating System
CSE 230 Intermediate Programming in C and C++ Input/Output and Operating System Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu Outline Use of some input/output
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationChapter 8 - Characters and Strings
1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library
More information.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..
.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!
More informationShould you know scanf and printf?
C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,
More informationCharacters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,
Strings Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters, decimal digits, special characters and escape
More informationC Libraries. Bart Childs Complementary to the text(s)
C Libraries Bart Childs Complementary to the text(s) 2006 C was designed to make extensive use of a number of libraries. A great reference for student purposes is appendix B of the K&R book. This list
More informationCS 261 Fall Mike Lam, Professor. Structs and I/O
CS 261 Fall 2018 Mike Lam, Professor Structs and I/O Typedefs A typedef is a way to create a new type name Basically a synonym for another type Useful for shortening long types or providing more meaningful
More informationCpSc 1111 Lab 5 Formatting and Flow Control
CpSc 1111 Lab 5 Formatting and Flow Control Overview By the end of the lab, you will be able to: use fscanf() to accept a character input from the user execute a basic block iteratively using loops to
More informationBasic I/O. COSC Software Tools. Streams. Standard I/O. Standard I/O. Formatted Output
Basic I/O COSC2031 - Software Tools C - Input/Output (K+R Ch. 7) We know how to do some basic input and output: getchar - reading characters putchar - writing characters printf - formatted output Input
More informationC for C++ Programmers
C for C++ Programmers CS230/330 - Operating Systems (Winter 2001). The good news is that C syntax is almost identical to that of C++. However, there are many things you're used to that aren't available
More informationStandard File Pointers
1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf
More informationStrings. Daily Puzzle
Lecture 20 Strings Daily Puzzle German mathematician Gauss (1777-1855) was nine when he was asked to add all the integers from 1 to 100 = (1+100)+(2+99)+... = 5050. Sum all the digits in the integers from
More informationBinghamton University. CS-211 Fall Input and Output. Streams and Stream IO
Input and Output Streams and Stream IO 1 Standard Input and Output Need: #include Large list of input and output functions to: Read and write from a stream Open a file and make a stream Close
More informationC Programming. Unit 9. Manipulating Strings File Processing.
Introduction to C Programming Unit 9 Manipulating Strings File Processing skong@itt-tech.edu Unit 8 Review Unit 9: Review of Past Material Unit 8 Review Arrays Collection of adjacent memory cells Each
More informationFundamentals of Programming
Fundamentals of Programming Lecture 6 - Array and String Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Array Generic declaration: typename variablename[size]; typename is
More informationProgramming in C. Session 8. Seema Sirpal Delhi University Computer Centre
Programming in C Session 8 Seema Sirpal Delhi University Computer Centre File I/O & Command Line Arguments An important part of any program is the ability to communicate with the world external to it.
More informationString constants. /* Demo: string constant */ #include <stdio.h> int main() {
Strings 1 String constants 2 /* Demo: string constant */ #include s1.c int main() { printf("hi\n"); } String constants are in double quotes A backslash \ is used to include 'special' characters,
More informationCSC209H Lecture 3. Dan Zingaro. January 21, 2015
CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without
More informationFile Handling. Reference:
File Handling Reference: http://www.tutorialspoint.com/c_standard_library/ Array argument return int * getrandom( ) static int r[10]; int i; /* set the seed */ srand( (unsigned)time( NULL ) ); for ( i
More informationCS246 Spring14 Programming Paradigm Files, Pipes and Redirection
1 Files 1.1 File functions Opening Files : The function fopen opens a file and returns a FILE pointer. FILE *fopen( const char * filename, const char * mode ); The allowed modes for fopen are as follows
More informationARRAYS(II Unit Part II)
ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful
More informationC Programming Language Review and Dissection III
C Programming Language Review and Dissection III Lecture 5 Embedded Systems 5-1 Today Pointers Strings Formatted Text Output Reading Assignment: Patt & Patel Pointers and Arrays Chapter 16 in 2 nd edition
More informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
More informationCpSc 1111 Lab 4 Formatting and Flow Control
CpSc 1111 Lab 4 Formatting and Flow Control Overview By the end of the lab, you will be able to: use fscanf() to accept a character input from the user and print out the ASCII decimal, octal, and hexadecimal
More informationCS 0449 Sample Midterm
Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)
More informationtoday cs3157-fall2002-sklar-lect05 1
today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical
More informationApproximately a Final Exam CPSC 206
Approximately a Final Exam CPSC 206 Sometime in History based on Kelley & Pohl Last name, First Name Last 4 digits of ID Write your section number: All parts of this exam are required unless plainly and
More informationLecture 8: Structs & File I/O
....... \ \ \ / / / / \ \ \ \ / \ / \ \ \ V /,----' / ^ \ \.--..--. / ^ \ `--- ----` / ^ \. ` > < / /_\ \. ` / /_\ \ / /_\ \ `--' \ /. \ `----. / \ \ '--' '--' / \ / \ \ / \ / / \ \ (_ ) \ (_ ) / / \ \
More informationLectures 5-6: Introduction to C
Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most
More informationCharacters and Strings
Characters and Strings 60-141: Introduction to Algorithms and Programming II School of Computer Science Term: Summer 2013 Instructor: Dr. Asish Mukhopadhyay Character constants A character in single quotes,
More informationupper and lower case English letters: A-Z and a-z digits: 0-9 common punctuation symbols special non-printing characters: e.g newline and space.
The char Type The C type char stores small integers. It is 8 bits (almost always). char guaranteed able to represent integers 0.. +127. char mostly used to store ASCII character codes. Don t use char for
More information