-1

The program will accept as a command line argument the name of a text file that will contain an arbitrary list of DNA strings. (ie. ~/assign1/filename.txt) DNA strings consist of a sequence of nucleotides (A,C,T, or G).

From a homework assignment. Is there a way to do this that doesn't involve the typical *argv[] argument? I ask because my instructor said this project should be completed "without any use of data structures."

smac89
  • 39,374
  • 15
  • 132
  • 179
  • 1
    I'd hesitate to call an array in C++ a data structure. – smac89 Sep 12 '19 at 02:45
  • Passing in a file name's not the only way to get a file into a program. You can also pipe the file into [stdin](https://stackoverflow.com/questions/3385201/confused-about-stdin-stdout-and-stderr) (eg: `myprogram < ~/assign1/filename.txt`) and read it with `std::cin` just like you would anything the user typed. – user4581301 Sep 12 '19 at 03:11
  • The instructor's no data structures is probably to prevent you from using [Standard Library containers](https://en.cppreference.com/w/cpp/container) and good ol' [`std::string`](https://en.cppreference.com/w/cpp/string/basic_string) for this assignment. Without easily resizable data structures, handling arbitrary length data can be tricky. You may find yourself having to write your own `string` class. Confirm the instructor's intent before going much further. Sucks to find out you did the assignment the hard way after handing it in. – user4581301 Sep 12 '19 at 03:12
  • `int argc, char **argv` are the function parameters for the function `main()`. One is an `int` and the other is an array of pointers with the first unused pointer set to `NULL`. Neither are `struct` structures. They are the proper way to provide command line arguments to your program. Your alternative is to take the filename as user-input. See [What should main() return in C and C++?](http://stackoverflow.com/questions/204476/) – David C. Rankin Sep 12 '19 at 03:27

1 Answers1

1

*argv[] is the way to go. It's the only C++ way to get command line arguments. And it's not a (user-defined) data structure.

A data structure would be at the very least a class or struct. Typically with nested class/struct and/or pointer between them.

Jeffrey
  • 11,063
  • 1
  • 21
  • 42
  • I'd consider it a data structure, but it's not a user-defined data structure, which is probably what the instructor was trying to avoid. – ShadowRanger Sep 12 '19 at 02:46