-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseResolution.c
More file actions
47 lines (38 loc) · 979 Bytes
/
parseResolution.c
File metadata and controls
47 lines (38 loc) · 979 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
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char resolution[18];// = "1024X768";
char *delims = "xX*";
char temp[32];
int width;
int height;
int first = 1;
char *result = NULL;
printf("Input the resolution as WIDTHxHEIGHT: ");
scanf("%s", resolution);
snprintf(temp, sizeof(temp), "%s", resolution);
/*
Use a temp buffer to process,
because the strtok will change the string when parsing
*/
result = strtok(temp, delims);
while(result!=NULL){
if(first){
width = atoi(result);
}
if(!first){
height = atoi(result);
}
first = 0;
result = strtok(NULL, delims);
}
/* width = strtol(temp, &temp, 10); */
/* if(*temp) */
/* temp++; */
/* height = strtol(temp, &temp, 10); */
printf("Width:%d, Height:%d\n", width, height);
printf("Resolution: %s\n", resolution);
return 0;
}