1234567891011121314151617181920212223242526 |
- #include <stdlib.h>
- #include <vector>
- #include <iostream>
- void echo(std::string a);
- std::string getBaseName(std::string s);
- int main(int argc, char *argv[]){
-
- if(argc < 2) {
- printf("Usage: %s {filename.ext}\n", argv[0]);
- return 1;
- }
- std::string userinput = argv[1];
- echo(getBaseName(userinput));
- }
- void echo(std::string a){
- printf("%s\n",a.c_str());
- }
- std::string getBaseName(std::string s) {
-
- for(int j=s.size();j>0;j--){
- if(s[j]== '.'){
- return s.substr(0,j);
- }
- }
- return s.substr(0,0);
- }
|