add string to given command line argument in C -


hello started programm in c , trying read file , give file name argument without ending .txt . want add .txt in code : ./myexample.exe file

if use file.txt there no problem dont know how change argv[1] tried char *n = argv[1] + ".txt"; doesnt works , dont know else..

int main(int argc, char* argv[]) {       char *n = argv[1] +".txt";       file *fp1;       fp1 = fopen(n , "r"); 

thats if use char *n = argv[1]+".txt"

error: invalid operands binary + (have 'char *' , 'char *')

you can't concatenate strings +. use strcpy , strcat:

char n[256]; strcpy(n, argv[1]); strcat(n, ".txt"); 

make sure n large enough hold filename + extension.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -