-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetc.c
More file actions
37 lines (32 loc) · 747 Bytes
/
etc.c
File metadata and controls
37 lines (32 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// Created by Aref on 19/06/29.
//
#include "etc.h"
int get_line(FILE *file, char *line) {
int c;
while ((c = fgetc(file)) != EOF) {
if (c == '\n') {
*line = 0;
return 1;
}
*(line++) = (char) c;
}
return 0;
}
int find(char *line, char x) {
for (int i = 0; line[i] != 0; i++)
if (line[i] == x)
return i;
return NOT_FOUND;
}
void from_to(char *old, char *new, int start, int end) {
for (int i = 0; i < end - start; i++)
new[i] = old[i + start];
new[end-start] = 0;
}
int compare(char *left, char *right) {
for (int i = 0; left[i] != 0 && right[i] != 0; i++)
if (left[i] != right[i])
return 0;
return 1;
}