From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

c programe to labview code

Solved!
Go to solution

Hello,

I am a beginner in labview. Can anyone please help me to convert the C programe code to labview code??

 

#include<stdio.h>
int main()
{
	int array[]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,1,1,1,1,1,1,1,1,1,1,20,0,40,50,1,1,1,1,1,1,1,1,1,1,5,6,7,8,1,2,3,4};
	int n = sizeof(array)/sizeof(array[0]);
	printf("size of array is :%d \n", n);
	int i;
	for(i=0;i<n;i++)
	{
		int j=0;
		int count=0;
		if(array[i]==1)
			{ 
			    j=i;
				count=1;
				while(array[j]==1)
				{
					j++;
				    count++;
				}
				if (count==10)
					printf("your  data is at  %d location in array \n",i+count);
			}
} return 0; }
Basically the code is finding a small sequence of data ,say 10 numbers from a large array of data, say 10000 numbers.
0 Kudos
Message 1 of 4
(2,681 Views)
Solution
Accepted by topic author sumeshkp03

I assume you have looked over this: http://www.ni.com/academic/students/learn-labview/

 

Give it a go and post what you have completed so far so that we can give you specific pointers.

0 Kudos
Message 2 of 4
(2,674 Views)
Solution
Accepted by topic author sumeshkp03

Hi sumesh,

 

Basically the code is finding a small sequence of data ,say 10 numbers from a large array of data, say 10000 numbers.

That's what that code does…

 

- You need a loop to run over your input array.

- You could use ArraySubset to read a subset of required length.

- You can compare this subset with your predefined pattern you are looking for.

- When both are the very same you can output this "pattern at location %d" message

 

That's a nice job to learn LabVIEW and some of it's very basic features! (Like autoindexing vs. non-indexing loop tunnels, comparison modes of compare functions, array handling and array functions…)

Show what you have tried and explain where you have failed!

(We will not do your homework!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 4
(2,654 Views)
Solution
Accepted by topic author sumeshkp03

Just to add to the confusion, we goes use Flatten To String on both the data and the search criteria and then use Search/Split String to do the search for us...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 4
(2,625 Views)