IP-06-String and Text File (1)
IP-06-String and Text File (1)
Output string:
C string:
printf( “%s”, <string> ).
printf(
puts( <string> ).
std::cout
std:: cout << <string> (C++).
std::string: std::cout
std::cout << <string>.
Fundamentals of Programming - Nguyễn Minh Huy 5
String
Practice: <ctype.h
<ctype.h>>
Count words: “the quick fox” 3 words.
Space: ‘ ‘, ‘\‘\t’, ‘\
‘\n’, ‘\
‘\r’ -> isspace
isspace(<char>).
(<char>).
Alphabet: ‘A’‘A’––‘Z’, ‘‘a’
a’--‘z
‘z’’ -> isalpha
isalpha(<char>).
(<char>).
Punctuation: ‘.‘, ‘,’, ‘?’, ‘!’,… -> ispunct
ispunct(<char>).
(<char>).
Digit: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, … -> isdigit
isdigit(<char>).
(<char>).
Capitalize words: “the quick fox” “The Quick Fox”.
Lower alphabet: ‘a’
a’--‘z
‘z’’ -> islower
islower(<char>).
(<char>).
Capitalize: <char> - 32 -> toupper
toupper(<char>).
(<char>).
if ((remove(
remove(“C: “C:\\\test.txt”)
test.txt”) == 0)
printf(“File
printf (“File deleted.
deleted.\\n”);
else
printf(“Error:
printf (“Error: cannot delete file.
file.\\n”);
if ((rename(
rename(“C:/test.txt”,
“C:/test.txt”, “C:/folder\
“C:/folder\\test2.txt”)
test2.txt”) == 0)
printf(“Succeeded.
printf (“Succeeded.\\n”);
else
printf(“Error.
printf (“Error.\\n”);
Input format:
Enter a sentence = “ today is a beautiful day ”
Output format:
“today is a beautiful day”
Input format:
S = tick tak tok
Output format:
3: k t
1: a c i o
PRIME.TXT
5 2 23 43 117
Screen output:
Word count: 3.
Number count: 2.