[英]int ** array changing value
So I have an int **
. 所以我有一个
int **
。 It contains pixel values. 它包含像素值。 What I'm trying to do is change the value of a set number of pixel values;
我想做的是更改一定数量的像素值的值; say the value is 90, I want to change it to the max level that it has to create a black edge of x amount of pixels.
假设该值为90,我想将其更改为创建x像素数量的黑边所必须达到的最大级别。 I've been messing around with it for the last hour and can't seem to figure out how to change the actual value inside the **
我在最后一个小时一直在弄乱它,似乎无法弄清楚如何更改**内的实际值
This is what I have so far: 这是我到目前为止的内容:
int pgmDrawEdge( int **pixels, int numRows, int numCols, int edgeWidth, char **header ){
int i=0, j=0, count=0;
int intensity=atoi(header[2]);
while(count<edgeWidth){
for(; i<numRows; i++){
for(; j<numCols; j++){
pixels[i][j]=intensity;
}
}
count++;
}
return 0;
}
This is the main function call: pgmDrawCircle(pixel, rows, cols, circleCenterRow, circleCenterCol, radius, header);
这是主要的函数调用:
pgmDrawCircle(pixel, rows, cols, circleCenterRow, circleCenterCol, radius, header);
I think I have the right idea, but like I mentioned above I just can't seem to figure out how to get the value to change. 我认为我有一个正确的想法,但是就像我上面提到的那样,我似乎无法弄清楚如何获得改变的价值。
I don't think I do, but do I need to allocate memory? 我不认为可以,但是我需要分配内存吗? It's being passed in from the main so I don't think I would need to since it is already full...correct?
它是从主服务器传递过来的,所以我认为不需要,因为它已经满了……对吗?
As per request here is pgmRead: 根据要求,这里是pgmRead:
int ** pgmRead( char **header, int *numRows, int *numCols, FILE *in ){
int i, j, temp, intensity;
fgets(header[0], maxSizeHeadRow, in);
fgets(header[1], maxSizeHeadRow, in);
fscanf(in, "%d %d", numCols, numRows);
fscanf(in, "%d", &intensity);
sprintf(header[2], "%d", intensity);
int **ptr=(int **)malloc(*numRows*sizeof(int *));
for(i=0; i<*numRows; i++){
ptr[i]=(int *)malloc(*numCols*sizeof(int));
}
for(i=0; i<*numRows; i++){
for(j=0; j<*numCols; j++){
fscanf(in, "%d", &temp);
ptr[i][j]=temp;
}
}
fclose(in);
return ptr;
}
In the main function: 在主要功能中:
int **pixel=NULL;
pixel=pgmRead(header, &rows, &cols, in);
if(strcmp(argv[1],"-e")==0){
printf("Edge Drawing\n");
pgmDrawEdge(pixel, rows, cols, edgeWidth, header);
}
your pgmDrawEdge pretty much works as this test shows. 如测试所示,您的pgmDrawEdge几乎可以正常工作。 So problem is elsewhere
所以问题在其他地方
#include <stdio.h>
#include <stdlib.h>
int pgmDrawEdge( int **pixels, int numRows, int numCols, int edgeWidth, char **header ){
int i=0, j=0, count=0;
int intensity=atoi(header[2]);
while(count<edgeWidth){
for(; i<numRows; i++){
for(; j<numCols; j++){
pixels[i][j]=intensity;
}
}
count++;
}
return 0;
}
int main() {
char *header[]={"abc","def","90"};
int *x[2];
int l1[]={1,2,3,4};
int l2[]={5,6,7,8};
x[0]=l1;
x[1]=l2;
pgmDrawEdge(x,2,4,99,header);
printf("result is %d should be %s", x[0][0], header[2] );
return(0) ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.