473,416 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Implementing Unix fmt ( ) function

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
0 1130

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jrefactors | last post by:
when people say unix programmer, does it mean they write programs in unix environment,and those programs are run in unix platform? it is not necessary they are using unix function calls? I heard...
7
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in...
70
by: Rajan | last post by:
Hi, I am trying to simulate a memcpy like this void* mem_cpy(void* dest, void* src, int bytes) { dest = malloc(bytes); } Now if I want to copy the bytes from src to dest, how do I copy these...
15
by: Alpha | last post by:
I was told that Unix API can only be called using C++, ATL and MFC. However, I was also told that C# can do that through Pinvoke to a DLL that interfaces with the Unix API. Can someone direct me...
5
by: Shastri | last post by:
Hi all, I was trying to implement chmod command(UNIX) in c. While passing arguments to the main function like : -r for reading the file -w for writing the file How can I compare the...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
13
by: Tristan Wibberley | last post by:
Hi I've got implementing overloaded operator new and delete pretty much down. Just got to meet the alignment requirements of the class on which the operator is overloaded. But how does one...
2
by: vin029 | last post by:
Hello all, i want to implent ZLIB function in c or c++ which should work on all environments , like windows, linux and unix , menas when i execute those cpp files it should ask the file to be...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.