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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Reading and Printing from char array
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

kemeyer

39 Posts

Posted - 07/20/2009 :  09:57:57 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

Iris_Bai

China
Posts

Posted - 07/20/2009 :  10:40:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000