Read Single Line (fgets())

2 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.31
List Price:  €119.45
You save:  €34.13
£73.01
List Price:  £102.22
You save:  £29.20
CA$136.78
List Price:  CA$191.50
You save:  CA$54.71
A$153.24
List Price:  A$214.55
You save:  A$61.30
S$127.49
List Price:  S$178.50
You save:  S$51
HK$784.91
List Price:  HK$1,098.91
You save:  HK$313.99
CHF 79.74
List Price:  CHF 111.64
You save:  CHF 31.89
NOK kr1,009.73
List Price:  NOK kr1,413.67
You save:  NOK kr403.93
DKK kr636.55
List Price:  DKK kr891.19
You save:  DKK kr254.64
NZ$165
List Price:  NZ$231.01
You save:  NZ$66
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,225.11
List Price:  ৳17,115.64
You save:  ৳4,890.53
₹8,575.15
List Price:  ₹12,005.55
You save:  ₹3,430.40
RM421
List Price:  RM589.42
You save:  RM168.42
₦154,205.57
List Price:  ₦215,893.97
You save:  ₦61,688.40
₨28,349.32
List Price:  ₨39,690.18
You save:  ₨11,340.86
฿3,250.72
List Price:  ฿4,551.14
You save:  ฿1,300.42
₺3,980.07
List Price:  ₺5,572.26
You save:  ₺1,592.19
B$548.94
List Price:  B$768.54
You save:  B$219.60
R1,777.65
List Price:  R2,488.79
You save:  R711.13
Лв166.77
List Price:  Лв233.48
You save:  Лв66.71
₩135,446.66
List Price:  ₩189,630.74
You save:  ₩54,184.08
₪336.99
List Price:  ₪471.81
You save:  ₪134.81
₱5,644.13
List Price:  ₱7,902.01
You save:  ₱2,257.88
¥14,425.26
List Price:  ¥20,195.95
You save:  ¥5,770.68
MX$1,886.26
List Price:  MX$2,640.84
You save:  MX$754.58
QR364.33
List Price:  QR510.08
You save:  QR145.75
P1,336.34
List Price:  P1,870.92
You save:  P534.58
KSh12,918.70
List Price:  KSh18,086.70
You save:  KSh5,168
E£4,959.19
List Price:  E£6,943.07
You save:  E£1,983.87
ብር13,503.01
List Price:  ብር18,904.76
You save:  ብር5,401.74
Kz91,186.38
List Price:  Kz127,664.58
You save:  Kz36,478.20
CLP$93,129.96
List Price:  CLP$130,385.67
You save:  CLP$37,255.71
CN¥716.34
List Price:  CN¥1,002.91
You save:  CN¥286.56
RD$5,946.58
List Price:  RD$8,325.46
You save:  RD$2,378.87
DA12,937.54
List Price:  DA18,113.08
You save:  DA5,175.53
FJ$224.05
List Price:  FJ$313.68
You save:  FJ$89.63
Q768.73
List Price:  Q1,076.25
You save:  Q307.52
GY$20,903.09
List Price:  GY$29,265.16
You save:  GY$8,362.07
ISK kr12,131.78
List Price:  ISK kr16,984.98
You save:  ISK kr4,853.20
DH902.48
List Price:  DH1,263.51
You save:  DH361.02
L1,692.76
List Price:  L2,369.93
You save:  L677.17
ден5,246.60
List Price:  ден7,345.46
You save:  ден2,098.85
MOP$808.27
List Price:  MOP$1,131.61
You save:  MOP$323.34
N$1,790
List Price:  N$2,506.08
You save:  N$716.07
C$3,678.54
List Price:  C$5,150.10
You save:  C$1,471.56
रु13,675.61
List Price:  रु19,146.41
You save:  रु5,470.79
S/354.78
List Price:  S/496.70
You save:  S/141.92
K412.31
List Price:  K577.25
You save:  K164.94
SAR375.01
List Price:  SAR525.03
You save:  SAR150.02
ZK2,366.43
List Price:  ZK3,313.10
You save:  ZK946.66
L433.20
List Price:  L606.50
You save:  L173.30
Kč2,111.08
List Price:  Kč2,955.60
You save:  Kč844.51
Ft34,094.24
List Price:  Ft47,733.30
You save:  Ft13,639.06
SEK kr950.02
List Price:  SEK kr1,330.06
You save:  SEK kr380.04
ARS$118,812.61
List Price:  ARS$166,342.40
You save:  ARS$47,529.79
Bs690.65
List Price:  Bs966.94
You save:  Bs276.28
COP$403,784.18
List Price:  COP$565,314.01
You save:  COP$161,529.82
₡50,412.50
List Price:  ₡70,579.51
You save:  ₡20,167.01
L2,611.75
List Price:  L3,656.56
You save:  L1,044.80
₲797,653.15
List Price:  ₲1,116,746.32
You save:  ₲319,093.17
$U4,019.51
List Price:  $U5,627.48
You save:  $U1,607.96
zł361.92
List Price:  zł506.70
You save:  zł144.78
Already have an account? Log In

Transcript

Hello, in this video, we are going to take a look at reading in a single line. So at the moment, it reads the entire file. And as you can see, it's on separate lines. So this is actually really simple. So instead of F read if we do f gets. So that's how you read a single line, and we don't need to specify the full size for this, we can get rid of that, you still need to open the file still need to close the at the end.

And now if we save that, and run it, we just get a single line. So if you want to get a novice single line, what we would recommend, or I would recommend is if, let's say for this echo decide, it's just easier to demonstrate what I'm going for this should still run the same way. If I duplicate this. That's great. So what it's done, if we need to do one more time And there we go, we've got the next line. So it's put a space there because there would have been a, this part right here.

So that's basically a, you know, an empty space character. And if we wanted to obviously put a break here, we could literally format these ourselves. So we could actually just put something like this. And now if we was to run it, there we go, we get the format that our file was originally in. So that's how you read a single line. And apart from that, and nothing more to it.

What I want you to do is figure out how to basically go through the entire file and read all of the line because one, there may be more than three lines. It may not be practical to do this. too, you may not know how many actual lines out in the fall. So low recommendation, look at using something like a loop which was one of the many control structures that was covered in the control structures part of this series. Feel free to you know, check that out if you haven't already done so or as a little refresher and figure out how to read every single line in the file and print it out in this fashion. Any questions feel free to drop me a message and as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.