By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,505 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,505 IT Pros & Developers. It's quick & easy.

Implementing Unix fmt ( ) function

P: n/a
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:
2 different line groups -> lines exceed 80 characters

-> 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[i]=bufIn[bufInCount];
bufInCount++;
}
j+=temp;
}
if(temp>=80){
for(i=0; i< chkNL-(temp-80); i++){
bufOut[k]=bufIn[i];
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.

Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.