Return-Path: william@bourbon.usc.edu Delivery-Date: Sun Oct 26 08:29:52 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9QFTqrI006204 for ; Sun, 26 Oct 2008 08:29:52 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9QFeVOH016893 for ; Sun, 26 Oct 2008 08:40:31 -0700 Message-Id: <200810261540.m9QFeVOH016893@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: Dos endline character Date: Sun, 26 Oct 2008 08:40:31 -0700 From: Bill Cheng Someone wrote: > If .ini file is created in dos then it has extra end line character ^M. > If we parse this file then it gives error, with stat function, as the > home directory path is appended with ^M. > > while grading, shall we assume that we will have all .ini created in Unix ? Yes! If you want your code to work with both types of file, assuming that my_string is a *null-terminated ASCII string* that represents a *line* of input, you can simply do: if (strlen(my_string) > 0 && my_str[strlen(my_string)-1] == '\r') { my_str[strlen(my_string)-1] == '\0'); } -- Bill Cheng // bill.cheng@usc.edu