The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Reading and Printing from char array

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
kemeyer Posted - 07/20/2009 : 09:57:57 AM
Origin Ver.7.0558 and Service Release (Select Help-->About Origin):
Operating System: Windows XP

I am reading in chars from a .txt file into a char array. Below is the code I am using. I and trying to write only a certain section of that char array into the script window or note window(using redirect) but I am having trouble finding the correct syntax to do so.

FILE *stream;
char buffer[81];

//open current c file to read line from:
stream = fopen( myFile, "r")
if(stream==NULL)
printf("The current C file cannot be opened.");

//read frist 80 chars and place them in "buffer":
char ch;
ch = fgetc(stream);
for(i=0; (i<80)&&(feof(stream)==0); i++){
buffer[i]=(char)ch;
ch=fgetc(stream);
}

//add null to end string
buffer[i] = '\0';
printf(%s/n", buffer);
fclose(stream)


However, rather than printing the whole buffer array, I want to print only a certain portion of it. I need to be able to search it for the characters 'c''o''m''m''e''n''t' in a row that denote the comment section of the information that I am reading from the .txt file, and then print the portion after that until a " character is reached. How can I print just that section?

Katie
1   L A T E S T    R E P L I E S    (Newest First)
Iris_Bai Posted - 07/20/2009 : 10:40:50 PM
Hi Katie,

Do you want to find a sub string in char array? See the following codes for example:

void strstr_ex1()
{
    char str1[] = "I saw 3 blind mice";
    char * pdest = strstr(str1, "blind");
    out_str(pdest); // output blind mice
}



Iris

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000