Implementing Unix fmt ( ) function

T

tempsl

Hello all,
I'm giving a try to implement unix fmt( ) function which can be used
to format strings.Since I'm really new to C programming this doesn't
look like a pretty trivial problem to me. I'm trying to implement this
function in such a way where 80 characters per line.
I tried different ways but still I couldn't find a way to
implement all different possibilities.
for example I tried to divide the lines that can be found in a
paragraph in to: -> lines doesn't exceed 80
characters
etc.

I'll copy some sample code lineds I've been trying so far:
if(chkNL<80){
k=temp;
temp+=chkNL;
if(temp<80){
bufOut[temp]=' ';
bufInCount=0;
for(i=j; i<j+chkNL; i++){
bufOut=bufIn[bufInCount];
bufInCount++;
}
j+=temp;
}
if(temp>=80){
for(i=0; i< chkNL-(temp-80); i++){
bufOut[k]=bufIn;
k++;
if(isalpha(bufIn[chkNL-(temp-80)+1])){
count=0;
while(!(isspace(bufOut[k]))){
bufOut[k]=' ';
k--;
count++;
}
....
.....
.....
If you have better implementation logic please let me (us) know.
thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,474
Latest member
VivianStuk

Latest Threads

Top