First lesson, learn how to indent code.
Code:
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
/* simple function to pause */
/* adapted from cplusplus.com */
int wait(float seconds)
{
clock_t endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < endwait) {
};
return (0);
}
void PrintNumber(char n, int r)
{
switch (atoi(&n)) {
/* For 0 */
case '0':
switch (r) {
case 0:
case 6:
printf("#####");
break;
case 1:
case 2:
case 3:
case 4:
case 5:
printf("# #");
break;
}
/* For 1 */
case '1':
switch (r) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
printf(" # ");
break;
}
/* For 2 */
case '2':
switch (r) {
case 0:
case 3:
case 6:
printf("#####");
break;
case 1:
case 2:
printf(" #");
break;
case 4:
case 5:
printf("# ");
break;
}
/* For 3 */
case '3':
switch (r) {
case 0:
case 3:
case 6:
printf("#####");
case 1:
case 2:
case 4:
case 5:
printf(" #");
break;
}
/* For 4 */
case '4':
switch (r) {
case 0:
case 1:
case 2:
printf("# #");
break;
case 3:
printf("#####");
break;
case 4:
case 5:
case 6:
printf(" #");
break;
}
/* For 5 */
case '5':
switch (r) {
case 0:
case 3:
case 6:
printf("#####");
break;
case 1:
case 2:
printf("# ");
break;
case 4:
case 5:
printf(" #");
break;
}
/* For 6 */
case '6':
switch (r) {
case 0:
case 3:
case 6:
printf("#####");
break;
case 1:
case 2:
printf("# ");
break;
case 4:
case 5:
printf("# #");
break;
}
/* For 7 */
case '7':
switch (r) {
case 0:
printf("#####");
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
printf(" #");
break;
}
/* For 8 */
case '8':
switch (r) {
case 0:
case 3:
case 6:
printf("#####");
break;
case 1:
case 2:
case 4:
case 5:
printf("# #");
break;
}
/* For 9 */
case '9':
switch (r) {
case 0:
case 3:
case 6:
printf("#####");
break;
case 1:
case 2:
printf("# #");
break;
case 4:
case 5:
printf(" #");
break;
}
}
}
int main()
{
FILE *gpsHandle;
char gpsString[105];
char str[7] = "$GPGGA";
char number[3];
int a, i, j;
int b = 1;
/* initialise connection to GPS receiver */
gpsHandle = fopen("gpsdata.txt", "r");
/* abort here if the file didn't open */
if (gpsHandle == NULL) {
printf("Couldn't open GPS data file\n");
return (0);
}
/* loop trying to get data */
while (!feof(gpsHandle)) {
/* read data line */
fgets(gpsString, 100, gpsHandle);
/* Tests first 6 characters in Data file individually to see if they are $GPGGA */
for (a = 0; a < 6; ++a) {
if (str[a] != gpsString[a]) {
/* If the first six characters are not $GPGGA sets b=0 and the next line is tested */
b = 0;
}
}
/* If the first six characters are $GPGGA sets b=1 */
if (b == 1)
/* Performs following operation while b=1 */
while (1) {
if (gpsString[a] == ',') {
char time[5] = "0000";
for (i = 0; i < 5; ++i)
time[i] = gpsString[a + i];
for (j = 0; j < 7; ++j)
for (i = a; i < a + 4; ++i)
PrintNumber(time[i], j);
break;
b = 1;
}
}
}
return (0);
}
Second lesson, read the manual page before using functions.
switch(atoi(&n))
Just because the compiler is "happy" that you managed to pass a parameter with the correct type to atoi(), it doesn't follow that atoi() itself is going to be happy at all when it fails to find an expected \0 to mark the end of the string.
You should have had
Code:
switch (atoi(&n))
....
default:
fprintf(stderr,"Huh? What!\n");
break;
Then you would have seen output caused by failure, as opposed to nothing at all.
If you're trying to do a char to int conversion on a single char, then
n - '0'
is all you need.