hi all
how can i truncate this...
1.2M /eee/uuu/123rwewv.zip
in this i want only "1.2M"
and
i want only 123rwewv.zip(must be after last "/")
can you help me please
thank you in advance
hi all
how can i truncate this...
1.2M /eee/uuu/123rwewv.zip
in this i want only "1.2M"
and
i want only 123rwewv.zip(must be after last "/")
can you help me please
thank you in advance
Perhaps you could try splitting the string into 2 separate components. I don't know how this could be done though (my known method is highly inefficient).
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express
is the text at 1.2M always going to be 4 characters? If so you could just copy the first 4 characters.
To get the end part of the string you could:
Get the line length.
Read backwards through the line until you reach the first / and save the index
Copy the section of that string after the index.
Concatenate it to the first part of the string you copied.
strchr() to find the first /
strrchr() to find the last /
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
using strchr and strrchr you can locate start and end of substrings you need and then
strcpy for the last part and strncpy for the first
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
sorry i did but, having some confusion..
i tried like this
char *s5, *split1, *file;
//file is the above file path.
s5=strrchr(file,"/");
strcpy(split1,s5);
can you please coding for me..
and also i wanna read first five char... of the path.(1.2M /eee/uuu/123rwewv.zip)
thank you in advance
Sure, we'll tell you when it's done... And while your waiting you could read the rules ?Originally Posted by munna_dude
> s5=strrchr(file,"/");
1. This generates some kind of error message right, something about pointer to int conversion?
Use single quotes.
Post actual code and error messages, not "something like these snippets"
> strcpy(split1,s5);
Where is split1 allocated?
Is it allocated at all?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.