Okay i checked the errno and it is 2
[insert]
Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int myatoi(const char *);
int main(void)
{
char c[10];
int sum = 0;
FILE *file;
file = fopen("C://Documents and Settings//ROHAN//Desktop//numbers.txt","r");
if(file == NULL)
{
printf("Error opening the file");
printf("\n%d", errno);
return errno;
}
else
{
printf("\nFile opened successfully");
while((fgets(c, 10, file)!= NULL))
sum += myatoi(c); // convert string to integer
}
printf("\n%d", sum);
printf("\nNow closing the file");
fclose(file);
printf("\nExiting");
return 0;
}
int myatoi(const char *str)
{
int result = 0;
while(isdigit(*str))
{
result *= 10;
result += *str - '0';
printf("\n%c \t%d", *str, *str);
str++;
}
return result;
}
What does this imply?