Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When programming in C, how do I write in my code to take a file and redirect it

ID: 3866477 • Letter: W

Question

When programming in C, how do I write in my code to take a file and redirect it to STDIN?

The command line would read as "AVLsort a < filename.txt" or "AVLsort d < filename.txt"

How can I take filename.txt to either sort the numbers in ascending "a" or descending "d" order?

I have already written the code for the ascending, descending etc., but the data from the filename.txt is not being read into those functions.

From the picture, I have written scanf("%s", str) since the filename.txt would be a string, but I don't understand how to print it out using these functions.

An example should look like this:

int a char str[201; printf("Enter a file: n"); scanf ( "%s " , str); /* Constructing tree given in the above figure / root = insert (root, 10); root insert ( root, 20); root = insert ( root, 30); root insert (root, 40); root = insert (root, 50); root= insert (root, 25); Double check height calculations during RR/LR/RRL/LRR (See case below. ...) root = insert (root, 5); root= insert (root, 4); /The constructed AVL Tree would be 10 25 50 printf("Pre Order Traversal of the Constructed AVL Tree is "); scanf ( "%s ", str); pre0rder(root); printf(" n"); printf("Post Order Traversal of the Constructed AVL Tree is "); scanf ("ss", str); post0rder (root); printf(" "); printf("Inln") printf("Ascending Order of Constructed AVL Tree is "); scanf("%s ", str); ascendingOrder (root); printf("Inn) printf( "Descending Order of Constructed AVL Tree is ") scanf("%s", str); descendingOrder(root); printf("n "); return ;

Explanation / Answer

/* the main function */ int main(void) { /* this is the beginning of a 'block', you read about those above */ int i = 6; /* this is the first variable of this 'block', 'i' */ { /* this is a new 'block', and because it's a different block, it has its own scope */ /* this is also a variable called 'i', but in a different 'block', because it's in a different 'block' than the old 'i', it doesn't affect the old one! */ int i = 5; printf("%d ", i); /* prints a '5' onto the screen */ } /* now we're back into the old block */ printf("%d ", i); /* prints a '6' onto the screen */ return 0; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote