I have come across the following problem.
I have a program which allows the user to create a .txt
file and add up to 10 ASCII values.
I am then closing the file, and re-opening in read mode. The point of this being that I am converting the inputted ASCII to integer using ATOI
.
The working code for this is provided below.
My problem is: I want to create some sort of array which stores these inputted ASCII values. BY doing so, this will enable me to call upon a function to check which of these ASCII values is smallest.
fp = fopen("c:\\CTEMP\\1.txt", "w+");
{
for (x = 0; x < 10; x++)
{
printf("\nType the word you want to add. Type exit to terminate: ");
scanf("%s", word); // word is declared as char word[10]
if (strcmp(word, "exit") == 0)
{
break;
}
fprintf(fp, "%s\n", word);
words++;
}
fclose(fp);
}
fp = fopen("C:\\CTEMP\\1.txt", "r");
while (!feof(fp))
{
fscanf(fp, "%s", &word);
number = atoi(word);
printf("\nstring is \t %s\n", word);
printf("integer is \t %d\n", number);
// location = find_minimum(array,number);
// minimum = array[location];
// printf("Minimum element location = %d and value = %d.\n", location + 1, minimum);
}
scanf_s("%d");
}
- Am I tackling the problem of finding the smallest ASCII value correctly?
- Is there any other way without creating another array to store the ASCII values?